Is it possible to call a specific method (or getting instance variables) without instance method from instance object in Ruby?
class Foo
def initialize(arg)
@bar = arg
end
end
f = Foo.new('test')
p f #=> "test" (in this case, get @bar variable without instance method)
For instance, if Example class is defined,
ex = Example.new
ex #=> #<Example:0x00000000000000>
I want to do, like this.
ex = Example.new('hello')
ex #=> "hello"
to_smethodattr_reader :barto get ruby to write the getter for you?s = String.new('foo'), I can access its value without instance methods #=> 'foo'.