Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- rbx
- rbx-19mode
- rbx-2
- jruby
- jruby-19mode

15 changes: 14 additions & 1 deletion lib/radix/operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,26 @@ class ::String
# The desired base.
#
# @return [Radix::Integer, Radix::Float]
def b(base)
def b_with_radix(base = nil)
# assume this is the ruby String#b being called if base is nil
return b_without_radix if base.nil? && respond_to?(:b_without_radix)

if index('.')
Radix::Float.new(self, base)
else
Radix::Integer.new(self, base)
end
end

# String#b in Radix conflicts with String#b in ruby 2.x
# to get around this without breaking the Radix API
# we can set up a method chain
if "".respond_to?(:b)
alias_method :b_without_radix, :b
alias_method :b, :b_with_radix
else
alias :b :b_with_radix
end
end

##
Expand Down