Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Last active December 30, 2015 08:09
Show Gist options
  • Select an option

  • Save zeroeth/7800651 to your computer and use it in GitHub Desktop.

Select an option

Save zeroeth/7800651 to your computer and use it in GitHub Desktop.
ruby magic
class Awesome
attr_accessor :first_var
def second_var= value
@second_var = value;
end
def second_var
@second_var
end
end
awesome = Awesome.new
awesome.first_var = 5
awesome.second_var = 5
class OtherThing
attr_accessor :ship
def initialize ship
self.ship = ship
end
# individual delegators
def first_var= value
ship.first_var = value
end
def first_var
ship.first_var
end
#...
end
class OtherThing
attr_accessor :ship
attr_accessor :first_var, :second_var
#...
def sync_attrs
[:first_var, :second_var].each do |method|
ship.send "#{method}=", self.send method
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment