Why doesn't Module.method_defined?(:method) work correctly?

why doesn't t
why doesn't it work
why doesn't my
why doesn't he want me
why doesn't youtube work
it doesn't matter carr
it doesn't matter sonic
why doesn't caffeine affect me

I'm trying to check if a method is defined in a module using Module.method_defined?(:method) and it is returning false it should be returing true.

module Something
  def self.another
    1
  end
end

Something.methods has 'another' listed but Something.method_defined?(:another) returns false.

Is this maybe not working because the method is defined on self? If this is the case is there another way to check if the method is defined on the module other than using method_defined??

To know whether the module has a module method, you can use respond_to? on the module:

Something.respond_to?(another)
=> true

method_defined? will tell you whether INSTANCES of the class with the module included responds to the given method.

Why doesn't the Leaning Tower of Pisa fall over?, If playback doesn't begin shortly, try restarting your device. Your browser does not currently Duration: 5:06 Posted: Dec 3, 2019 So why doesn’t our government? Related. Opinion. Opinion How Trump and the CDC are turning teachers into COVID-19's newest villains. Over the past weeks,

Modules methods are defined in its metaclass. So you can also check for method inclusion with:

k = class << Something; self; end # Retrieves the metaclass
k.method_defined?(:another)  #=> true

You can read more about it in Understanding Ruby Metaclasses.

Why doesn't Trump try harder to solve the coronavirus crisis?, The president has failed at the one task that could help him achieve all of his goals — confronting the pandemic with a clear strategy and� It's no surprise that President Donald Trump says he won't follow CDC recommendations to wear a mask to stop the spread of coronavirus, writes Michael D'Antonio. Ever the defiant and self-involved

I'm adding my version of the answer

Using the singleton_methods method:

module Something
  def self.another
  end
end

Something.singleton_methods.include?(:another) #=> true, with all parent modules
Something.singleton_methods(false).include?(:another) #=> true, will check only in the Something module

Why doesn't Python have a main function? | by Pawan Jain, if __name__ == '__main__' is not function. And the author doesn't recommend it to write this either. Want to know the reasons? but how to write� Why China’s Growth Sometimes Doesn’t Add Up Unless Chinese consumers start spending again and businesses start investing, 3.2% growth might be hard to sustain

IT Doesn't Matter, As information technology's power and ubiquity have grown, its strategic importance has diminished. The way you approach IT investment and management will� Robert De Niro on Tuesday trashed Donald Trump’s floundering handling of the coronavirus pandemic, slamming the president as a “lunatic” who “doesn’t even care how many people die” so long as he wins the 2020 election.

Why Doesn't This HR Department Get Any Respect?, And within a year, two of the five remaining senior managers had resigned as well. “It doesn't matter why those two left,” Robinson told Rose between bites of� PHILADELPHIA — A bubble can’t contain Major League Baseball. That’s the reasonable contention that Rob Manfred made Monday to the MLB Network as concerns grew about the league’s viability

Why does "Why doesn't it work?" become "Why does it not work , You form questions in English by inverting the subject and the verb. For the OP's two sentences, the verbs you use in this inversion are does� Why More Testing Doesn't Explain the Rise in COVID-19 in Several New U.S. Hotspots. By Chris Wilson and Tara Law June 19, 2020 4:03 PM EDT A

Comments
  • Perhaps I am reading this wrong, but shouldn't it be Something.respond_to?(:another) so another is a symbol. Otherwise wouldn't another cause an undefined error?
  • The diagram on that site is confusing to say the least. What does it mean by the instance 'inheriting' the methods from the class? seems like wrong terminology to me. Also what does it mean by the arrow labeled instance_eval pointing to the metaclass? instance_eval evaluation does not happen on the metaclass, it happens on the instance - the only exception being the behaviour of def in an instance_eval which instead defines methods on the metaclass.
  • Thank you! Not sure why the other answer go the checkmark. This is the way to actually do it.