Irb/TipsAndTricks
http://www.rubygarden.org/ruby?Irb/TipsAndTricks
Ruby使ããªã誰ããæç¨ãã¦ãã(ã¨æããã)irbã®tipsãªã©ãæ¸ããã¦ããrubygardenã®1ãã¼ã¸ãªãã§ãããããã®riã使ã£ã¦ãªãã¡ã¬ã³ã¹å¼ãæ¹æ³ãè¶
便å©ï¼refeã«å¤ãããé¼»è¡ãåºãã»ã©ä¾¿å©ã ã£ãã®ã§ç´¹ä»ãrefeã¨ã¯ã
ã¯ã©ã¹åã¨ã¡ã½ããåãã Ruby ã®ãªãã¡ã¬ã³ã¹ããã¥ã¢ã«ã®ã¨ã³ããªãå¼ããã³ãã³ãã©ã¤ã³ç¨ã®ãã¼ã«ã§ããèªã¿ã¯ãããµããã ri ããã¯ã£ã¦æ¥æ¬èªã»RD ã«å¯¾å¿ããããã®ã§ãã
http://i.loveruby.net/ja/prog/refe.html
ã¨ããéæ¨ããä½ã®ãã¼ã«ã§ãæè¿ã¯gemåãããã¦ãã®ã§gem install refeã§ãä¸çºã¤ã³ã¹ãã¼ã«ãã§ãã¾ããã§ãå ã»ã©ã®ãµã¤ãã§æ¸ããã¦ãriã®ç®æãã¡ãã£ã¨å¤æ´ãã¦ã~/.irbrcã«
module Kernel def r(arg) puts `refe #{arg}` end private :r end class Module def r(meth = nil) if meth if instance_methods(false).include? meth.to_s puts `refe #{self}##{meth}` else super end else puts `refe #{self}` end end end
ãªã©ã¨æ¸ãã¦ããã¨
>> Array.r :inspect Array < Object#inspect --- inspect ãªãã¸ã§ã¯ãã人éãèªããå½¢å¼ã«å¤æããæååãè¿ãã¾ãã çµã¿è¾¼ã¿é¢æ° p ã¯ããã®ã¡ã½ããã®çµæã使ç¨ã㦠ãªãã¸ã§ã¯ãã表示ãã¾ãã => nil >> String.r :each String#each --- each([rs]) {|line| ... } --- each_line([rs]) {|line| ... } æååä¸ã®åè¡ã«å¯¾ãã¦ç¹°ãè¿ãã¾ããè¡ã®åºåã㯠rs ã«æå® ããæååã§ããã®ããã©ã«ãã¯å¤æ° $/ ã®å¤ã§ãã å line ã«ã¯åºåãã®æååãå«ã¿ã¾ãã rs ã« nil ãæå®ããã¨è¡åºåããªãã¨ã¿ãªãã¾ãã 空æåå "" ãæå®ããã¨é£ç¶ããæ¹è¡ãè¡ã®åºåãã¨ã¿ãªãã¾ã (ãã©ã°ã©ãã¢ã¼ã)ã self ãè¿ãã¾ãã => nil
ã¨irbããå¼ãã¦ä¾¿å©ï¼ã¾ãã~/.irbrcã§
require 'irb/completion'
ãã¦è£å®ãæå¹ã«ãã¦ããã¨symbolã§ã¡ã½ããåãè£å®ã§ãããã
Array.r :del[tab] #=> Array.r :delete ã¨è£å®ããã
ã¨ãã§ãã¦è¶ 便å©ï¼Rubyããã°ã©ãã³ã°æã«ã¯å¸¸æirbãç«ã¡ä¸ãã¦ãã人éã«ã¨ã£ã¦ã¯ä½¿ãã©ãããå¤ããã§ãã