当然黑 python 只能一种也好 XD
a = [1, 2, 3]
1. a[0] #=> 1
2. a.at(0) #=> 1
3. a.fetch(0) #=> 1
4. a.first #=> 1
5. a.slice(0) #=> 1
6. a[-3] #=> 1
#10 楼 @adamshen 能试着列一列吗?感觉挺有趣的。我暂时只能想起这些:
class Demo
def self.class_method1
end
class << self
def class_method2
end
end
end
Demo.instance_eval do
def class_method3
end
end
Demo.class_eval do
def self.class_method4
end
end
module DemoModule
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def class_method5
end
end
end
class Demo
include DemoModule
end
class C
end
C.define_singleton_method(:singletom_method) do
puts 'the seventh way to define class methods'
end