Created
April 5, 2012 02:50
-
-
Save jimsynz/2307632 to your computer and use it in GitHub Desktop.
Response to das-0050-shorter-class-syntax.mov
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 UClass | |
def self.<(*keys) | |
define_method(:initialize) do |*args| | |
keys.each_with_index do |key,i| | |
instance_variable_set("@#{key}".to_sym,args[i]) | |
end | |
end | |
self | |
end | |
def self.>(method,&block) | |
define_method(method, &block) | |
self | |
end | |
end | |
UserPresenter = UClass.<(:user).>(:full_name){[@user.first_name,@user.last_name] * ' '} | |
describe UserPresenter do | |
let (:user) { stub(:user, first_name: 'Bob', last_name: 'Smith')} | |
it "presents users' full name" do | |
UserPresenter.new(user).full_name.should == 'Bob Smith' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment