Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
# This isn't necessarily "better", or even "useful" in any way, just sort of fun.
class Object
# I like how I can actually create methods with these names.
def if
@__if_result = yield self
self
end
def then
@__if_result ? yield self : self
end
def else
@__if_result ? self : yield self
end
end
# code sample from elsewhere.
# http://github.com/nateware/redis-objects/blob/master/ATOMICITY.rdoc
@course = Course.find(1)
if @course.num_students < 30
@course.course_students.create!(:student_id => 101)
@course.num_students += 1
@course.save!
else
# course is full
end
# revised version.
Course.find(1).if { |course|
course.num_students < 30
}.then { |course|
course.course_students.create!(:student_id => 101)
course.num_students += 1
}.else { |course|
# Do nothing!
}.save!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.