I have an instance method defined on a class:
class Foo
def is_linux
# some code...
# returns true or false
end
end
And i would like to call this method in a Module:
class Foo
module Dog
is_linux? ? puts "Is Linux" : puts "Is Windows"
end
end
This gives me the following error:
NoMethodError: undefined method `is_linux?' for Foo::Foo:Module
I know i can write
class Foo
module Dog
Foo.new.is_linux? ? puts "Is Linux" : puts "Is Windows"
end
end
But i was wondering if there is a way for the module to access the current instance?
Basically you’ll need somehow to “share” your utility methods.
I would suggest to put them into a mixin: