I am trying to simulate Eiffel’s ability to make methods in a class only
available to specific other classes. I know it is probably impossible to
make methods only visible to certain other classes, but is there a way
to make a class throw an exception if called by the wrong class?
For instance:
class Foo
def bar
if calling_class.class != some_other_class.class
raise An_Entry_Exception.new
end
â?¦rest of class
end
end
Specifically is there a way to see what the class of whatever is calling
a method is (like the variable ‘calling_class’ above)? Or does anyone
know of a project that simulates this functionality?
On Jul 2, 2006, at 3:30 PM, kevin kinnett wrote:
def bar
know of a project that simulates this functionality?
–
Posted via http://www.ruby-forum.com/.
Google Binding.of_caller. It’s an evil hack. Good luck.
On Mon, 3 Jul 2006, kevin kinnett wrote:
raise An_Entry_Exception.new
end
â?¦rest of class
end
end
Specifically is there a way to see what the class of whatever is calling
a method is (like the variable ‘calling_class’ above)? Or does anyone
know of a project that simulates this functionality?
class Foo
def bar
unless [One, Two, Three].include? self.class
raise An_Entry_Exception.new
end
end
end
-a
Or does anyone know of a project that simulates this functionality?
Yes, see:
http://www.rcrchive.net/rcr/show/198
http://raa.ruby-lang.org/project/pubsub
Dan Amelang