def self.def1
end
how to lock a ruby definition to use it one instance at a time?
def self.def1
end
how to lock a ruby definition to use it one instance at a time?
You create “singleton methods” (don’t confuse this with Java/GoF
“singletons”):
x = []
y = []
def x.sayHello; puts “Hello world!” end
x.sayHello
y.sayHello # NoMethodError
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs