以下都是在资料中摘抄下来的,有的目前还没有理解透,慢慢理解。
1、nil是对象(java中null不是对象)
2、整数是个完整的对象,如:3.abs
3、实例由类自己参建,通用工厂:
1、nil是对象(java中null不是对象)
2、整数是个完整的对象,如:3.abs
3、实例由类自己参建,通用工厂:
def create_from_factory(factory)
factory.new
end
obj = create_from_factory(Array)
4、 Methods can be added to classes at any point,随处为类添加方法,下面是为Integer添加even?方法
class Integer
def even?
(self % 2) == 0
end
end
p (1..10).select { |n| n.even? }
# => [2, 4, 6, 8, 10]
5、Singleton methods are defined on individual objects, not classes.
class Dog
end
rover = Dog.new
fido = Dog.new
def rover.speak
puts "Red Rover"
end
rover.speak # => "Red Rover"
fido.speak # => NoMethodError
5、Lanaguage Typing Systems
Java is
- Strongly,
- Statically,
- Manifestly
typed.
Ruby is
- Strongly,
- Dynamically,
- Implicitly
typed.