Skip to content

Instantly share code, notes, and snippets.

@zaeleus
Created March 16, 2012 17:34
Show Gist options
  • Save zaeleus/2051317 to your computer and use it in GitHub Desktop.
Save zaeleus/2051317 to your computer and use it in GitHub Desktop.
diff --git a/kernel/bootstrap/string.rb b/kernel/bootstrap/string.rb
index a6f066f..d26370c 100644
--- a/kernel/bootstrap/string.rb
+++ b/kernel/bootstrap/string.rb
@@ -1,5 +1,14 @@
# -*- encoding: us-ascii -*-
+module Rubinius
+ module String
+ def self.to_dbl(str, strict)
+ Rubinius.primitive :string_to_dbl
+ raise ArgumentError, "invalid value for Float"
+ end
+ end
+end
+
class String
attr_reader :num_bytes
attr_reader_specific :num_bytes, :bytesize
@@ -10,7 +19,7 @@ class String
end
def to_f
- to_dbl(false)
+ Rubinius::String.to_dbl(self, false)
end
alias_method :convert_float, :to_f
@@ -130,9 +139,4 @@ class String
Rubinius.primitive :string_resize_capacity
raise PrimitiveFailure, "String#resize_capacity failed"
end
-
- def to_dbl(strict)
- Rubinius.primitive :string_to_dbl
- raise ArgumentError, "invalid value for Float"
- end
end
diff --git a/kernel/common/kernel18.rb b/kernel/common/kernel18.rb
index e84d2f0..71cb581 100644
--- a/kernel/common/kernel18.rb
+++ b/kernel/common/kernel18.rb
@@ -132,7 +132,7 @@ module Kernel
when Float
obj
when String
- obj.to_dbl(true)
+ Rubinius::String.to_dbl(obj, true)
else
coerced_value = Rubinius::Type.coerce_to(obj, Float, :to_f)
if coerced_value.nan?
diff --git a/kernel/common/kernel19.rb b/kernel/common/kernel19.rb
index 6db929d..fb0337c 100644
--- a/kernel/common/kernel19.rb
+++ b/kernel/common/kernel19.rb
@@ -220,7 +220,7 @@ module Kernel
when Float
obj
when String
- obj.to_dbl(true)
+ Rubinius::String.to_dbl(obj, true)
else
Rubinius::Type.coerce_to(obj, Float, :to_f)
end
diff --git a/vm/builtin/string.cpp b/vm/builtin/string.cpp
index 83c16ed..23996d0 100644
--- a/vm/builtin/string.cpp
+++ b/vm/builtin/string.cpp
@@ -913,8 +913,8 @@ namespace rubinius {
return Float::from_cstr(state, str, strict);
}
- Float* String::to_dbl_prim(STATE, Object* strict) {
- Float* value = String::to_f(state, strict);
+ Float* String::to_dbl(STATE, Object* self, String* str, Object* strict) {
+ Float* value = str->to_f(state, strict);
if(value->nil_p()) {
return (Float*)Primitives::failure();
diff --git a/vm/builtin/string.hpp b/vm/builtin/string.hpp
index 4bb80c1..212f8ee 100644
--- a/vm/builtin/string.hpp
+++ b/vm/builtin/string.hpp
@@ -178,7 +178,7 @@ namespace rubinius {
Float* to_f(STATE, Object* strict = cTrue);
// Rubinius.primitive :string_to_dbl
- Float* to_dbl_prim(STATE, Object* strict);
+ static Float* to_dbl(STATE, Object* self, String* str, Object* strict);
Integer* to_i(STATE, Fixnum* base = Fixnum::from(0), Object* strict = cTrue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment