Created
April 13, 2022 22:10
-
-
Save gerardogc2378/14997b8864b47f199d9aa62c4bf7c856 to your computer and use it in GitHub Desktop.
La pieza
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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