Last active
August 29, 2015 14:13
-
-
Save hasanen/69f0f1a06c74017d5a77 to your computer and use it in GitHub Desktop.
N+1 problem
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
class Industry | |
def initialize name, parent=nil | |
@name, @parent = name, parent | |
end | |
def full_name | |
[parent_name, @name].reject{|n| n.empty?}.join(' / ') | |
end | |
def parent_name | |
@parent.nil? ? '' : @parent.full_name | |
end | |
end | |
ind1 = Industry.new 'Name 1' | |
ind2 = Industry.new 'Name 2', ind1 | |
ind3 = Industry.new 'Name 3', ind2 | |
puts ind3.full_name # => "Name 1 / Name 2 / Name 3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment