Created
April 30, 2013 15:02
-
-
Save kyuden/5489300 to your computer and use it in GitHub Desktop.
Symbol#to_proc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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