Skip to content

Instantly share code, notes, and snippets.

@tejo
Created November 20, 2014 14:14
Show Gist options
  • Save tejo/3c28e77a0ec074c46e42 to your computer and use it in GitHub Desktop.
Save tejo/3c28e77a0ec074c46e42 to your computer and use it in GitHub Desktop.
# encoding: utf-8 #per caratteri italiani
class MotherNature
attr_accessor :animals
def initialize
@animals = []
end
def search_animal(query)
puts "albo devi farmi tu, non so come cercare un animale di nome #{query}, so solo che io conosco #{@animals.count} animali"
end
def add_animal(name, type, specie)
@animals << Animal.new(name, type, specie)
end
end
class Animal
attr_accessor :name, :type, :specie
def initialize(name, type, specie)
@name = name
@type = type
@specie = specie
end
end
#displays the animal you entered (there is now only archive the dolphin)
def which_print_animal
puts "do you want print which animal?"
puts ">"
@mn.search_animal($stdin.gets.chomp)
insert_or_read
end
# first domand do you want read or add?
def insert_or_read
puts"Do you want read the archivie or add the animals?"
puts ">"
answer = $stdin.gets.chomp
if answer.include? "read"
which_print_animal
elsif answer.include? "add"
add_animals
else
puts "input incorrect, retry"
insert_or_read
end
end
#intro of program
def intro
puts """
#####The MAGIC WORLD OF ANIMALS####
###############V1.0################
"""
insert_or_read #launch the question
end
@mn = MotherNature.new()
@mn.add_animal("delfino", "mammifero", "marino")
@mn.add_animal("tigre", "mammifero", "pericoloso")
#launch
intro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment