Is this the right way of calling an Instance method from a class method? Here the instance_var is passed with the Name object. I want to invoke func1 from the instance_var object passed to the class method.
I wrote this :
Class Name
def initialize
@name
end
def func1(value)
puts value
end
def self.func2(instance_var,val)
instance_var.func1(val)
end
end
How do you call
func2
?Your code has a small error. You wrote
Class
insteadclass
. WithClass
you get a syntax error.This code works:
Your
will create an empty variable
@name
. It will never get a value. To assign a value you need: