I have the following test which I must pass:
def test_can_find_by_arbitrary_fields
assert @library.respond_to? :find_by_artist
assert !@library.respond_to?(:find_by_bitrate)
@library.add_song({ :artist => 'Green Day',
:name => 'American Idiot',
:bitrate => 192 })
assert @library.respond_to?(:find_by_bitrate)
end
and I am not sure how I can do it.
I tried doing:
def respond_to?(method)
if self.public_methods.include? method
true
elsif (method == :find_by_bitrate)
define_method :find_by_bitrate, ->(default = nrb) { @songs.select |a| a[:bitrate] == nrb }
false
else
false
end
but it says "define_method is undefined". Are there any ways I can define the find_by_bitrate
method?