Alex Rivera | Logout

Given a class, see if instance has method (Ruby)

Asked 2010-07-21T20:04:46.633
253

I know in Ruby that I can use respond_to? to check if an object has a certain method.

But, given the class, how can I check if the instance has a certain method?

i.e, something like

Foo.new.respond_to?(:bar)

But I feel like there's gotta be a better way than instantiating a new instance.

Edit
Report

1 Answer

5

Try Foo.instance_methods.include? :bar

answered 2010-07-21T20:11:38.557

Your Answer