Skip to content

Commit

Permalink
Make Kernel#Integer compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Oct 17, 2013
1 parent 48f622d commit 24e3e62
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions corelib/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,16 @@ def instance_variables
}
end

def Integer(str)
`parseInt(str)`
def Integer(value, base = `undefined`)
if String === value
`parseInt(value, base)`
elsif value.respond_to? :to_int
value.to_int
elsif value.respond_to? :to_i
value.to_i
else
raise TypeError, "can't convert #{value.class} into Integer"
end
end

def is_a?(klass)
Expand Down

0 comments on commit 24e3e62

Please sign in to comment.