Last active
August 29, 2015 13:57
-
-
Save adammcarth/9717472 to your computer and use it in GitHub Desktop.
Using ("dynamic"?) classes in ruby...
This file contains 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
# Active Record lets you do things like: | |
Post.find(3).title | |
#=> "Hello, world!" | |
# Cool. So my question is, how exactly do you setup a class that allows the | |
# programmer to use there own keyword? My use case: | |
def get(type, id) | |
# blah | |
end | |
get("preferencs", 4) | |
#=> { "fav_color" => "blue", "food" => "pasta" } ... I HAVE THIS WORKING | |
get("preferences", 4).fav_color | |
#=> blue | |
# Somewhere, somehow, I need to be able to access the information returned by | |
# get("prefrences", 4) AND be able to access the "fav_color" keyword (in this case). | |
# Is that some extra code I need in my get method? Or is a seperate class required? |
This file contains 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
# This is the inheritence structure I am working with | |
module Get | |
def get(type, id) | |
# blah | |
end | |
end | |
class Main | |
extend Get | |
end | |
# Main.get(blah) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment