Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### (1) Conditional branching ###
- hello1 = nil
- unless hello1
- hello1 = 'hello1'
- end
- ### (2) Use Proc ###
- hello2 ||= Proc.new do
- 'hello2'
- end.call
- ### (3) Use lambda ###
- hello3 ||= lambda {
- 'hello3'
- }.call
- ### (4) Separate out the method ###
- def func
- 'hello4'
- end
- hello4 ||= func
- ### OUTPUT ###
- puts hello1 # -> "hello1" (Conditional)
- puts hello2 # -> "hello2" (Proc)
- puts hello3 # -> "hello3" (Lambda)
- puts hello4 # -> "hello4" (Method)
Add Comment
Please, Sign In to add comment