Created
March 23, 2013 15:35
-
-
Save andrewsardone/5228121 to your computer and use it in GitHub Desktop.
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 'delegate' | |
require 'test/unit' | |
# http://www.saturnflyer.com/blog/jim/2013/03/21/ruby-delegate-rb-secrets/ | |
class Displayer < SimpleDelegator | |
# alias_method from post originally out of order: | |
# alias_method :__getobj__, :object | |
alias_method :object, :__getobj__ | |
def name_with_location | |
"#{object.name} of #{object.city}" | |
end | |
end | |
class TestDisplayer < Test::Unit::TestCase | |
def test_name_with_location | |
jim = Struct.new(:name, :city).new("Jim", "Some City") | |
displayer = Displayer.new(jim) | |
assert_equal "Jim of Some City", displayer.name_with_location | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment