q1:
irb(main):001:0> tmp=(1..10).to_a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] irb(main):002:0> tmp.each.class => Enumerator irb(main):003:0> tmp.select.class => Enumerator irb(main):004:0> tmp.map.class => Enumerator irb(main):005:0>
q2: 如何定义 tmp=(1..10).to_a; puts tmp[2,5] 里面的[]方法?
举例:
irb(main):002:0> class Fixnum irb(main):003:1> def + (other) irb(main):004:2> self irb(main):005:2> end irb(main):006:1> end => :+ irb(main):007:0> 1+2 => 1 irb(main):006:0> 1+10 => 1 irb(main):005:0>
what' s ruby?(ref: ruby编程语言)
时间: 2024-10-18 21:21:36