Skip to content

Instantly share code, notes, and snippets.

@matsumonkie
Created June 12, 2014 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsumonkie/8af92f5ac91cefc29ab2 to your computer and use it in GitHub Desktop.
Save matsumonkie/8af92f5ac91cefc29ab2 to your computer and use it in GitHub Desktop.
forwordable
require 'forwardable'
class Vehicle
extend Forwardable
def_delegators :@vehicle, :name, :power, :color
def to_s
"#{name} with #{power} HP"
end
def initialize(vehicle)
@vehicle = vehicle
end
end
Car = Struct.new(:name, :power, :color)
def main
ferrari = Car.new('Ferrari', 125, 'red')
vehicle = Vehicle.new(ferrari)
puts vehicle.name # Ferrari
puts vehicle.to_s # Ferrari with 125 HP
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment