-
-
Save markburns/fbea61114176667f453fecc24d75c936 to your computer and use it in GitHub Desktop.
Defining methods at the top level scope
This file contains 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
#!/usr/bin/env ruby | |
def do_something_probably_just_in_this_script! | |
puts "called in #{self} from #{caller[-1]}" | |
end | |
module HeresAnother | |
def this_one | |
puts "called in #{self} from #{caller[-1]}" | |
end | |
end | |
include HeresAnother | |
do_something_probably_just_in_this_script! | |
require "./b" |
This file contains 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 Something | |
def a_method | |
send :do_something_probably_just_in_this_script! | |
end | |
end | |
Something.new.a_method | |
String.new.send :do_something_probably_just_in_this_script! | |
puts String.private_methods.grep /do_somet/ | |
puts String.new.private_methods.grep /do_som/ | |
send :this_one | |
This file contains 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
$ ruby temp.rb | |
called in main from temp.rb:15:in `<main>' | |
called in #<Something:0x007f8a3b82d9b8> from temp.rb:17:in `<main>' | |
called in from temp.rb:17:in `<main>' | |
do_something_probably_just_in_this_script! | |
do_something_probably_just_in_this_script! | |
called in main from temp.rb:17:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment