Skip to content

Instantly share code, notes, and snippets.

@agargiulo
Created March 2, 2015 19:19
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 agargiulo/465dd45a30161d9027e3 to your computer and use it in GitHub Desktop.
Save agargiulo/465dd45a30161d9027e3 to your computer and use it in GitHub Desktop.
Playing around with Ruby classes and modules.
module Foo
class << self
def logger
@logger ||= Logger.new($stdout)
end
end
class FunThing
def self.is_fun? item
item.is_a? FunThing
end
end
class LameThing
def self.is_fun? item
FunThing.is_fun? item
end
def self.log_thing
Foo.logger.debug 'This does work, right?'
## How do I run the above line without explicitly calling Foo.logger?
## Sort of like how I can just call FunThing.is_fun? instead of Foo::FunThing.is_fun?
# logger.debug 'This will not actually work'
end
end
end
fun = Foo::FunThing.new
puts Foo::FunThing.is_fun? fun
lame = Foo::LameThing.new
puts Foo::LameThing.is_fun? lame
Foo::LameThing.log_thing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment