Skip to content

Instantly share code, notes, and snippets.

@joelibaceta
Last active May 14, 2016 02:57
Show Gist options
  • Save joelibaceta/d4fc9c5dd8fe0a50f07a5eb27c2e1d47 to your computer and use it in GitHub Desktop.
Save joelibaceta/d4fc9c5dd8fe0a50f07a5eb27c2e1d47 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment