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
| class String | |
| def perform | |
| yield self | |
| end | |
| end | |
| #=== block ==== | |
| block_string = "Hey there, " | |
| block_string.perform do |n| |
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
| class String | |
| def perform code | |
| code.call self | |
| end | |
| end | |
| #===proc: storing into a variable==== | |
| proc_string1 = "Hey there, " | |
| proc_code = Proc.new do |n| | |
| puts n + "from a proc storing into a variable!" |
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
| class String | |
| def perform code | |
| code.call(self) | |
| end | |
| end | |
| #===lambda method==== | |
| lambda_string = "Hey there, " | |
| lambda_code = lambda do |n| | |
| puts n + "from a lambda!" |
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
| class String | |
| def perform code | |
| code.call(self) | |
| end | |
| end | |
| #=== method ==== | |
| method_string = "Hey there, " | |
| def func n |
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
| def proc_return | |
| Proc.new { return "proc1"}.call | |
| return "proc2 I AM HERE!" | |
| end | |
| def lambda_return | |
| lambda { return "lambda1" }.call | |
| return "lambda2 I AM HERE!" | |
| end |
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
| def proc_return | |
| return "proc1" | |
| return "proc2 I AM HERE!" | |
| end |
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
| def what_class(&code) | |
| return code.class | |
| end | |
| def func | |
| "nothing" | |
| end | |
| puts (what_class do end) | |
| puts Proc.new {}.class | |
| puts lambda{}.class | |
| puts method(:func).class |
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
| def argument_check_correct(&code) | |
| code.call("a1","a2") | |
| end | |
| def argument_check_wrong(&code) | |
| code.call("a1") | |
| end | |
| argument_check_correct do |a1,a2| | |
| puts "block: arguments received: #{a1}, #{a2.class}" |
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
| def argument_check_correct(code) | |
| code.call("a1","a2") | |
| end | |
| def argument_check_wrong(code) | |
| code.call("a1") | |
| end | |
| proc1 = Proc.new{|a1,a2| puts "proc: arguments received: #{a1}, #{a2.class}"} | |
| argument_check_correct proc1 |
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
| def argument_check_correct(code) | |
| code.call("a1","a2") | |
| end | |
| def argument_check_wrong(code) | |
| code.call("a1") | |
| end | |
| lambda1 = lambda {|a1,a2| puts "proc: arguments received: #{a1}, #{a2.class}"} | |
| argument_check_correct lambda1 |
OlderNewer