ROR开发小技巧

2011年12月25日

ruby-1.9.2-p180 :055 > File.join("lib/","ruby","gem.rb")
 => "lib/ruby/gem.rb"

ruby-1.9.2-p180 :058 > [1,2,3] - [1,2]
 => [3] 

ruby-1.9.2-p180 :059 > [1,2,3] & [1,2]
 => [1, 2] 

ruby-1.9.2-p180 :060 > [1,2,3] + [1,2,3,4]
 => [1, 2, 3, 1, 2, 3, 4]

ruby-1.9.2-p180 :066 > %w(a d c d 1 2 3)
 => ["a", "d", "c", "d", "1", "2", "3"]

ruby-1.9.2-p180 :074 > Hash["a",1,"b",2]
 => {"a"=>1, "b"=>2} 

ruby-1.9.2-p180 :075 > Hash[*["a",1,"b",2]]
 => {"a"=>1, "b"=>2} 

ruby-1.9.2-p180 :075 > Array("a".."z").select.with_index {|x,i| i%3 == 2}
 => ["c", "f", "i", "l", "o", "r", "u", "x"]

# coding:utf-8
# unicode转义
"" << 0x6f22 #=> 漢

class Object
  # returns instance methods of current object's class and its singleton methods
  def lm # abbr of local methods
    self.methods.sort - self.class.superclass.instance_methods
  end
end

参考:http://ruby-china.org/topics/541
 
Leave a comment
Comments
  1. 6b6493fb30da43861137874deb13cca9?s=48

    Bianca :

    I can already tell that's gonna be super hpeflul.

    2012年04月21日

     
  2. B68c251902144ef63fbb679b193016d7?s=48

    GolfFoete :

    Some of these factors can include the soil type and pH on your land to shade conditions, and the slope of the lawn area. <a href=http://lopolikumieo.com>cocksureness</a> Stuck on synonyms? http://lopolikumieo.com They can be paired with almost anything. <

    2012年03月26日

     
YOUR COMMENT
Name: Name is required
E-mail:
Comment:
Comment is required

Home Blog Delicious Github Flickr About Contact

© Miclle.Zheng . Powered by Forest Chalet