Created
June 12, 2014 21:17
-
-
Save matsumonkie/8af92f5ac91cefc29ab2 to your computer and use it in GitHub Desktop.
forwordable
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
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