Getting an object’s methods without the inherited methods

test = SomeObject.new
test.methods - test.class.superclass.new.methods

Or is there a shorter, less convoluted way?

Update November 12th: yes there seems to be…

puts String.instance_methods(false)

From the Ruby For Rails Book, page 254, paragraph 9.8.1….

But: String.instance_methods(false).size = 83 , whereas (test.methods – test.class.superclass.new.methods).size = 102 (with test a string object).

>> puts (test.methods - test.class.superclass.new.methods - String.instance_methods(false)).sort
<
<=
>
>=
all?
any?
between?
collect
detect
each_with_index
entries
find
find_all
grep
inject
map
max
member?
min
partition
reject
select
sort
sort_by
zip
=> nil
>> exit

The difference seems to be the methods of the mixed in modules…

One Response to “Getting an object’s methods without the inherited methods”

  1. Using Rails for Batch processes (example: Moneybird export via API and command-line) — Written along the rails Says:

    [...] ← Getting an object’s methods without the inherited methods [...]

Leave a Reply