Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix to_h

  • Loading branch information...
commit 7a6147e046b5c326097140437919477d317042a2 1 parent 120a57c
@marcandre authored
View
8 Rakefile
@@ -22,12 +22,6 @@ task :spec, :path, :action do |t, args|
puts "*** mspec returned with unexpected results:"
puts result
puts "Command was:", cmd
- puts "Mspec version: " + `mspec --version`
- puts "Testing basic mspec:", `mspec rubyspec/core/array/append_spec.rb`
- puts "Testing basic mspec:", `mspec ci rubyspec/core/array/append_spec.rb`
- puts "Testing basic mspec:", `mspec ci -r rbconfig rubyspec/core/array/append_spec.rb`
- puts "Testing basic mspec:", `mspec ci -r rbconfig -I lib -r set_version/2.0.0 rubyspec/core/array/append_spec.rb`
- puts "Testing basic mspec:", `mspec ci -r rbconfig -I lib -r set_version/2.0.0 -r backports/2.0.0/nil/to_h rubyspec/core/array/append_spec.rb`
fail "Unexpected output from mspec"
end
_, ex, p, f, e = data = match.captures.map{|x| x.to_i}
@@ -50,7 +44,7 @@ task :spec, :path, :action do |t, args|
end
task :all_spec do # Necessary because of argument passing bug in 1.8.7
- Rake::Task[:spec].invoke('nil/*')
+ Rake::Task[:spec].invoke
end
task :spec_tag, :path do |t, args|
View
2  lib/backports/1.8.7/io/each_char.rb
@@ -1,4 +1,6 @@
unless IO.method_defined? :each_char
+ require 'enumerator'
+
class IO
def each_char
return to_enum(:each_char) unless block_given?
View
36 lib/backports/1.8.7/method/name.rb
@@ -5,10 +5,10 @@ class Method
attr_accessor :name, :receiver, :owner
def unbind_with_additional_info
- unbind_without_additional_info.tap do |unbound|
- unbound.name = name
- unbound.owner = owner
- end
+ unbound = unbind_without_additional_info
+ unbound.name = name
+ unbound.owner = owner
+ unbound
end
Backports.alias_method_chain self, :unbind, :additional_info
end
@@ -17,32 +17,32 @@ class UnboundMethod
attr_accessor :name, :owner
def bind_with_additional_info(to)
- bind_without_additional_info(to).tap do |bound|
- bound.name = name
- bound.owner = owner
- bound.receiver = to
- end
+ bound = bind_without_additional_info(to)
+ bound.name = name
+ bound.owner = owner
+ bound.receiver = to
+ bound
end
Backports.alias_method_chain self, :bind, :additional_info
end
module Kernel
def method_with_additional_info(name)
- method_without_additional_info(name).tap do |bound|
- bound.name = name.to_s
- bound.receiver = self
- bound.owner = self.class.ancestors.find{|mod| mod.instance_methods(false).include? bound.name}
- end
+ bound = method_without_additional_info(name)
+ bound.name = name.to_s
+ bound.receiver = self
+ bound.owner = self.class.ancestors.find{|mod| mod.instance_methods(false).include? bound.name}
+ bound
end
Backports.alias_method_chain self, :method, :additional_info
end
class Module
def instance_method_with_additional_info(name)
- instance_method_without_additional_info(name).tap do |unbound|
- unbound.name = name.to_s
- unbound.owner = ancestors.find{|mod| mod.instance_methods(false).include? unbound.name}
- end
+ unbound = instance_method_without_additional_info(name)
+ unbound.name = name.to_s
+ unbound.owner = ancestors.find{|mod| mod.instance_methods(false).include? unbound.name}
+ unbound
end
Backports.alias_method_chain self, :instance_method, :additional_info
end
View
4 lib/backports/1.8.7/string/bytes.rb
@@ -1,3 +1 @@
-require 'backports/tools'
-
-Backports.alias_method String, :bytes, :each_byte
+require 'backports/1.8.7/string/each_byte'
View
2  lib/backports/1.8.7/string/each_byte.rb
@@ -1,3 +1,5 @@
require 'backports/tools'
Backports.make_block_optional String, :each_byte, :test_on => "abc"
+
+Backports.alias_method String, :bytes, :each_byte
View
1  lib/backports/1.8.7/string/each_char.rb
@@ -1,5 +1,6 @@
unless String.method_defined? :each_char
require 'backports/tools'
+ require 'enumerator'
class String
def each_char
View
2  lib/backports/1.8.7/string/each_line.rb
@@ -1,3 +1,5 @@
require 'backports/tools'
Backports.make_block_optional String, :each_line, :test_on => "abc"
+
+Backports.alias_method String, :lines, :each_line
View
4 lib/backports/1.8.7/string/lines.rb
@@ -1,3 +1 @@
-require 'backports/tools'
-
-Backports.alias_method String, :lines, :each_line
+require 'backports/1.8.7/string/each_line'
View
7 lib/backports/1.8.7/string/upto.rb
@@ -1,12 +1,13 @@
unless ("abc".upto("def", true){} rescue false)
require 'backports/tools'
+ require 'enumerator'
class String
def upto_with_exclusive(to, excl=false)
return upto_without_exclusive(to){|s| yield s} if block_given? && !excl
- enum = Range.new(self, to, excl).to_enum
- return enum unless block_given?
- enum.each{|s| yield s}
+ r = Range.new(self, to, excl)
+ return r.to_enum unless block_given?
+ r.each{|s| yield s}
self
end
Backports.alias_method_chain self, :upto, :exclusive
View
1  lib/backports/1.9.1/enumerable/each_with_index.rb
@@ -1,5 +1,6 @@
if Enumerable.instance_method(:each_with_index).arity.zero?
require 'backports/tools'
+ require 'enumerator'
module Enumerable
def each_with_index_with_optional_args_and_block(*args)
View
2  lib/backports/2.0.0/hash/to_h.rb
@@ -1,7 +1,7 @@
unless Hash.method_defined? :to_h
class Hash
def to_h
- self
+ self.class == Hash ? self : {}.replace(self)
end
end
end
View
6 lib/backports/2.0.0/struct/to_h.rb
@@ -1,9 +1,9 @@
unless Struct.method_defined? :to_h
class Struct
def to_h
- Hash[
- self.class.members.each{|m| [m.to_sym, self[m]]}
- ]
+ h = {}
+ self.class.members.each{|m| h[m.to_sym] = self[m]}
+ h
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.