Skip to content

Instantly share code, notes, and snippets.

@iamajvillalobos
Created June 10, 2016 08:54
Show Gist options
  • Save iamajvillalobos/946353777dbb1a1eb7edccfbfdce31c1 to your computer and use it in GitHub Desktop.
Save iamajvillalobos/946353777dbb1a1eb7edccfbfdce31c1 to your computer and use it in GitHub Desktop.
class Robot
NAME_LETTERS = ("A".."Z").to_a
NAME_NUMBERS = (100..999).to_a
attr_accessor :name
def initialize
reset
end
def reset
self.name = build_robot_name
end
private
def build_robot_name
firstname = NAME_LETTERS.product(NAME_LETTERS).sample
lastname = NAME_NUMBERS.sample
name_generator(firstname, lastname)
end
def name_generator(firstname, lastname)
remove_name_combinations(firstname, lastname)
firstname.join('') + lastname.to_s
end
def remove_name_combinations(firstname, lastname)
remove_firstname(firstname)
remove_lastname(lastname)
end
def remove_firstname(firstname)
firstname.each do |letter|
NAME_LETTERS.delete(letter)
end
end
def remove_lastname(lastname)
NAME_NUMBERS.delete(lastname)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment