Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try block #88

Closed
wants to merge 1 commit into from
Closed

Try block #88

wants to merge 1 commit into from

Conversation

raggi
Copy link
Contributor

@raggi raggi commented Oct 26, 2010

Add support for Object#try to just invoke a block if no method to be called has been given. This replaces the need for other hacks like unless_blank? { code } and if_present? { code } off of an existing method and paradigm.

Example:

@person = Struct.new(:first_name, :last_name).new("David", "Heinemeier Hansson")
@person.try { |p| "#{p.first_name} #{p.last_name}" } # => "David Heinemeier Hansson"

…is to be called. Kind of like a tap_if_present.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant