Created
April 13, 2012 16:10
-
-
Save matthuhiggins/2377997 to your computer and use it in GitHub Desktop.
Using Object#tap to create scopes
This file contains hidden or 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
| Braintree::Configuration.tap do |config| | |
| if settings = YAML.load_file(Rails.root.join('config', 'braintree.yml'))[Rails.env] | |
| config.environment = :sandbox | |
| config.merchant_id = settings['merchant_id'] | |
| config.public_key = settings['public_key'] | |
| config.private_key = settings['private_key'] | |
| end | |
| end |
This file contains hidden or 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
| <div class="ninja> | |
| <div>Name: <%= @ninja.name %></div> | |
| <% @ninja.victims.last.tap do |victim| %> | |
| <div>Last victim: <%= victim.name %></div> | |
| <div>Date killed: <%= victim.killed_at %></div> | |
| <% end %> | |
| </div> |
This file contains hidden or 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
| test 'has_weapon_skill' do | |
| build(:bad_ass, name: 'Chuck Norris').tap do |bad_ass| | |
| assert bad_ass.has_weapon_skill?('uzi') | |
| assert !bad_ass.has_weapon_skill?('nunchucks') | |
| end | |
| build(:bad_ass, name: 'Bruce Lee').tap do |bad_ass| | |
| assert !bad_ass.has_weapon_skill?('uzi') | |
| assert bad_ass.has_weapon_skill?('nunchucks') | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment