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 goal of this exercise is work on identifying abstraction which helps simplify, document, | |
# and separate the concerns going on in file. | |
# | |
# Exercise: | |
# * Find related ideas in the below code | |
# * Abstract them out (methods, modules, classes, etc, you pick!) | |
# * If you find multiple ways, then do a separate gist for each way. | |
# * Rinse repeat until you see no other ways. | |
# |
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
gotoExternalApp = function () { | |
var options = Environment.appOptions; | |
console.log ("Launching " + options.appName); | |
ExternalApp.launch(options); | |
}; | |
gotoExternalApp(); |
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
"appOptions": { | |
"appStoreUrl":"https://itunes.apple.com/us/app/app_name/idXXX", | |
"iosUrlScheme":"app_name://launchedfromthisappwiththeseoptions", | |
"androidAppID":"com.XXX.app_name", | |
"appName":"App Name" | |
} |
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
## Contrived Example | |
# Will the thing float? | |
class Thing | |
attr_accessor :mass, :volume | |
def will_i_float? | |
(mass / volume) < 1 | |
end |
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
##Class | |
class User | |
belongs_to :group, inverse_of: :member | |
end | |
class Group | |
# inverse_of because we are adding options to the relationship that prevent | |
# automatic guessing of the inverse | |
has_many :members, class_name: "User", inverse_of: :user |
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
##Class | |
class User | |
has_one :profile # inverse_of :profile not necessary in 4.1+ | |
end | |
class Profile | |
belongs_to :user # inverse_of :user not necessary in 4.1+ | |
end |
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
##Class | |
class User | |
has_one :profile | |
has_one :avatar, through: :profile | |
end | |
class Profile | |
belongs_to :user | |
has_one :avatar |
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
##Class | |
class User | |
has_one :profile | |
has_many :avatars, through: :profile | |
end | |
class Profile | |
belongs_to :user | |
has_many :avatars |
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
##Class | |
class User | |
has_and_belongs_to_many :groups | |
end | |
class Group | |
has_and_belongs_to_many :groups | |
end |
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
##Class | |
class User | |
has_many :memberships | |
has_many :groups, through: :memberships | |
end | |
class Membership | |
belongs_to :user | |
belongs_to :group |
OlderNewer