Ruby - Dream of dream - 66RPG

一行控的记录

所谓一行控,狭义上应该说是把写几行的东西变成一行吧……

广义上其实就是简洁而已……

Ruby中,提供了许多函数可以让脚本更加简洁。


for item in array
...
end

 => array.each {|item| ... }


for index in 0...array.size
...
end

=> array.each_index {|index| ... }


for count in 0...time
...
end

=> time.times {|count| ... }


for one in -time..time
   for two in -time..time
...
   end
end

=> (-time).step(time) {|one| (-time).step(time) {|two| ... } }


def method(*args)
...
end

=> define_method(:method) {|*args| ... }


 




Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee