Skip to content

Instantly share code, notes, and snippets.

@kyuden
Created April 30, 2013 15:02
Show Gist options
  • Save kyuden/5489300 to your computer and use it in GitHub Desktop.
Save kyuden/5489300 to your computer and use it in GitHub Desktop.
Symbol#to_proc
#ProcBlok変換復習
3.times{p 'hoge'}
proc = Proc.new{ p 'hoge'}
3.times{proc.call}
3.times(&proc)
def my_method(&hoge)
hoge.call('hoge','hoge')
end
my_method{ |a, b| p [a, b] }
#Symbol#to_proc呼び出し
class Myclass
attr_accessor :id
def initialize
@id = Time.now.to_i
end
end
data1 = Myclass.new
data2 = Myclass.new
data3 = Myclass.new
@data = [data1, data2, data3]
p @data.map{|data| p data.id }
p @data.map(&:id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment