Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Example: passing a proc into a method
- def give_me_a_proc(pr)
- puts 'Before call the proc'
- pr.call
- puts 'After calling the proc'
- end
- noisy_proc = proc { puts 'Called me noisy' }
- give_me_a_proc(noisy_proc)
- # The above code will print:
- # Before call the proc
- # Called me noisy
- # After calling the proc
- # Example: returning a proc from a method
- def fancy_proc_maker
- proc { puts 'Called me fancy' }
- end
- fancy_proc = fancy_proc_maker
- fancy_proc.call
- # The above code will print:
- # Called me fancy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement