类的扩展和继承 class Fixnum def dosome(str) puts str end def abs puts "覆盖了原有的方法" end end puts 1.class 1.dosome("动态添加的方法") 1.abs#覆盖原有的方法 freeze冻结对象 class Test attr_accessor :value end t=Test.new t.value=1 a="test" a.freeze #a<<…
赋值: ruby支持并行赋值,即允许在赋值表达式中出现多余一个值和多于一个的变量: x,y=1,2a,b=b,ax,y,z=[1,2,3] (python同样可以正常上面的语句). Methods in Ruby are allowed to return more than one value, and parallel assignmentis helpful in conjunction with such methods. For example:# Define a method to…