Last active
May 14, 2016 02:57
-
-
Save joelibaceta/d4fc9c5dd8fe0a50f07a5eb27c2e1d47 to your computer and use it in GitHub Desktop.
Kind of Ruby Developers
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
# 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 | |
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
# 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 | |
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
# 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 |
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
# 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 |
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
# 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