笔记一:
代码中包含变量,类和方法,统称为语言构建(language construct)。
# test.rb
class Greeting
def initialize(text)
text = text
end
def welcome
text
end
end
my_obj = Greeting.new("hello")
puts my_obj.class
puts my_obj.class.instance_methods(false) #false means no
1.如何声明一个子类
代码如下:
class Treasure < Thing
这样Thing类中的属性name,descr iption都被Treasure继承
2.以下三种方式传入父类initialize方法的参数分别是什么?
代码如下:
# This passes a, b, c to the superclass
def initialize( a, b, c, d, e, f )
super( a, b, c )
end
# This passes a, b, c to