Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View array_if.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Source: http://gist.github.com/281687#file_array_if.rb
class Array
def if(predicate)
predicate ? self.first : self.last
end
end
 
if __FILE__ == $0
require 'test/unit'
class ArrayTest < Test::Unit::TestCase
def test_should_return_expensive
price = 100
assert_equal "expensive", ["expensive","cheap"].if(price > 50)
end
 
def test_should_return_cheap
price = 25
assert_equal "cheap", ["expensive","cheap"].if(price > 50)
end
end
end
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.