Skip to content

Instantly share code, notes, and snippets.

@gerardogc2378
Created April 13, 2022 22:10
Show Gist options
  • Save gerardogc2378/14997b8864b47f199d9aa62c4bf7c856 to your computer and use it in GitHub Desktop.
Save gerardogc2378/14997b8864b47f199d9aa62c4bf7c856 to your computer and use it in GitHub Desktop.
La pieza
class Word
def initialize(w = "foo", m = "bar")
@w = w
@m = m
end
def word
@w
end
def meaning
@m
end
end
class Dictionary
def initialize(a = [])
@a = a
end
def find_meaning(n)
r = @a.select{ |item| item.word == n }
return r.first.meaning if r
end
end
apple = Word.new('apple', 'A fruit')
p apple.word == 'apple' # => true
p apple.meaning == 'A fruit' # => true
car = Word.new('car', 'A transport')
dictionary = Dictionary.new([apple, car])
p dictionary.find_meaning('apple') == 'A fruit' # => true
p dictionary.find_meaning('car') == 'A transport' # => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment