Skip to content

@mhaley /array_if.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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.