Skip to content

Instantly share code, notes, and snippets.

@phluid61
Created February 25, 2016 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phluid61/70c75302512630642d36 to your computer and use it in GitHub Desktop.
Save phluid61/70c75302512630642d36 to your computer and use it in GitHub Desktop.
ruby 'require' scope
require_relative 'b'
Foo.new.foo
p ['Main in a.rb', $global, bar, Baz.qux]
class Foo
def foo
require_relative 'c'
p ['Foo#foo in b.rb', $global, bar, Baz.qux]
end
end
$global = 'global'
def bar
'bar'
end
class Baz
def self.qux
'Baz.qux'
end
end
$ ruby -v a.rb
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
["Foo#foo in b.rb", "global", "bar", "Baz.qux"]
["Main in a.rb", "global", "bar", "Baz.qux"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment