Kind of Ruby Developers
# The Java Driven Developer
class Person
@name = ""
def get_name
return @name
end
def set_name
return @name
end
end
# Result
person = Person.new
person.set_name = "Juan"
person.get_name == "Juan" # true
person.get_name == "Carlos" # false
# The Friendly Style Driven Developer
class Person
attr_accessor :name
def name_is_equal_to(name)
name == @name
end
end
# Result
person = Person.new
person.name = "Juan"
person.name_is_equal_to "Juan" #true
person.name_is_equal_to "Carlos" #false
# The Metaprogramming Driven Developer
class Person
def method_missing(method, *args, &block)
parsed_method = method.to_s.split("_")
if method.to_s[-1] == "?"
return instance_variable_get("@name") == parsed_method.last[0..-2]
else
instance_variable_set("@name", parsed_method[1]) if parsed_method.first == "is"
end
end
end
# Result
person = Person.new
person.is_Juan
person.is_Juan? # true
person.is_Carlos? # false
# The Minimalist Driven Developer
class Person
attr_accessor :name
end
# Result
person = Person.new
person.name = "Juan"
person.name == "Juan" # true
person.name == "Carlos" # false
# Functional Driven Developer
Person = Struct.new(:name)
# Result
person = Person.new("Juan")
person.name = "Juan"
person.name == "Juan" # true
person.name == "Carlos" # false