marcandre-backports 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CHANGELOG.rdoc +7 -0
  2. data/README.rdoc +31 -36
  3. data/Rakefile +4 -27
  4. data/VERSION.yml +2 -2
  5. data/backports.gemspec +52 -32
  6. data/lib/backports/{argf.rb → 1.8.7/argf.rb} +8 -8
  7. data/lib/backports/{array.rb → 1.8.7/array.rb} +26 -43
  8. data/lib/backports/1.8.7/dir.rb +7 -0
  9. data/lib/backports/{enumerable.rb → 1.8.7/enumerable.rb} +22 -38
  10. data/lib/backports/1.8.7/enumerator.rb +19 -0
  11. data/lib/backports/1.8.7/env.rb +3 -0
  12. data/lib/backports/1.8.7/fixnum.rb +11 -0
  13. data/lib/backports/1.8.7/float.rb +4 -0
  14. data/lib/backports/1.8.7/hash.rb +23 -0
  15. data/lib/backports/1.8.7/integer.rb +23 -0
  16. data/lib/backports/{io.rb → 1.8.7/io.rb} +8 -7
  17. data/lib/backports/1.8.7/kernel.rb +39 -0
  18. data/lib/backports/{method.rb → 1.8.7/method.rb} +8 -8
  19. data/lib/backports/1.8.7/module.rb +7 -0
  20. data/lib/backports/1.8.7/numeric.rb +3 -0
  21. data/lib/backports/1.8.7/object_space.rb +5 -0
  22. data/lib/backports/1.8.7/range.rb +4 -0
  23. data/lib/backports/{regexp.rb → 1.8.7/regexp.rb} +2 -1
  24. data/lib/backports/1.8.7/string.rb +90 -0
  25. data/lib/backports/1.8.7/struct.rb +3 -0
  26. data/lib/backports/1.8.7/symbol.rb +6 -0
  27. data/lib/backports/1.8.7.rb +4 -0
  28. data/lib/backports/1.9/array.rb +12 -0
  29. data/lib/backports/1.9/enumerable.rb +8 -0
  30. data/lib/backports/1.9/enumerator.rb +15 -0
  31. data/lib/backports/1.9/hash.rb +15 -0
  32. data/lib/backports/1.9/integer.rb +3 -0
  33. data/lib/backports/1.9/kernel.rb +11 -0
  34. data/lib/backports/1.9/string.rb +39 -0
  35. data/lib/backports/{symbol.rb → 1.9/symbol.rb} +1 -6
  36. data/lib/backports/1.9.rb +5 -0
  37. data/lib/backports/rails/array.rb +6 -0
  38. data/lib/backports/rails/enumerable.rb +12 -0
  39. data/lib/backports/rails/hash.rb +31 -0
  40. data/lib/backports/rails/kernel.rb +12 -0
  41. data/lib/backports/rails/module.rb +6 -0
  42. data/lib/backports/rails/string.rb +42 -0
  43. data/lib/backports/rails.rb +4 -0
  44. data/lib/backports/tools.rb +117 -0
  45. data/lib/backports.rb +4 -15
  46. data/test/enumerator_test.rb +3 -3
  47. data/test/test_helper.rb +1 -3
  48. metadata +48 -32
  49. data/lib/backports/core_ext.rb +0 -61
  50. data/lib/backports/dir.rb +0 -7
  51. data/lib/backports/enumerator.rb +0 -43
  52. data/lib/backports/env.rb +0 -3
  53. data/lib/backports/fixnum.rb +0 -11
  54. data/lib/backports/float.rb +0 -4
  55. data/lib/backports/hash.rb +0 -64
  56. data/lib/backports/integer.rb +0 -25
  57. data/lib/backports/kernel.rb +0 -55
  58. data/lib/backports/module.rb +0 -30
  59. data/lib/backports/numeric.rb +0 -3
  60. data/lib/backports/object_space.rb +0 -5
  61. data/lib/backports/range.rb +0 -4
  62. data/lib/backports/string.rb +0 -167
  63. data/lib/backports/struct.rb +0 -3
  64. /data/lib/backports/{binding.rb → 1.8.7/binding.rb} +0 -0
  65. /data/lib/backports/{gc.rb → 1.8.7/gc.rb} +0 -0
  66. /data/lib/backports/{proc.rb → 1.8.7/proc.rb} +0 -0
  67. /data/lib/backports/{process.rb → 1.8.7/process.rb} +0 -0
@@ -0,0 +1,117 @@
1
+ # Methods used internally by the backports.
2
+
3
+ module Backports
4
+ # Adapted from Pragmatic's "Programming Ruby" (since their version was buggy...)
5
+ def self.require_relative(relative_feature)
6
+ file = caller.first.split(/:\d/,2).first
7
+ if /\A\((.*)\)/ =~ file # eval, etc.
8
+ raise LoadError, "require_relative is called in #{$1}"
9
+ end
10
+ require File.expand_path(relative_feature, File.dirname(file))
11
+ end
12
+
13
+ # Metaprogramming utility to make block optional.
14
+ # Tests first if block is already optional when given options
15
+ def self.make_block_optional mod,*methods
16
+ options = methods.last.is_a?(Hash) ? methods.pop : {}
17
+ methods.each do |selector|
18
+ unless mod.method_defined? selector
19
+ warn "#{mod}##{selector} is not defined, so block can't be made optional"
20
+ next
21
+ end
22
+ unless options.empty?
23
+ test_on = options[:test_on] || self.new
24
+ next if (test_on.send(selector, *options.fetch(:arg, [])) rescue false)
25
+ end
26
+
27
+ arity = mod.instance_method(selector).arity
28
+ last_arg = []
29
+ if arity < 0
30
+ last_arg = ["*rest"]
31
+ arity = -1-arity
32
+ end
33
+ arg_sequence = ((0...arity).map{|i| "arg_#{i}"} + last_arg + ["&block"]).join(", ")
34
+
35
+ alias_method_chain(mod, selector, :optional_block) do |aliased_target, punctuation|
36
+ mod.module_eval <<-end_eval
37
+ def #{aliased_target}_with_optional_block#{punctuation}(#{arg_sequence})
38
+ return to_enum(:#{aliased_target}_without_optional_block#{punctuation}, #{arg_sequence}) unless block_given?
39
+ #{aliased_target}_without_optional_block#{punctuation}(#{arg_sequence})
40
+ end
41
+ end_eval
42
+ end
43
+ end
44
+ end
45
+
46
+ # Modified to avoid polluting Module if so desired
47
+ # (from Rails)
48
+ def self.alias_method_chain(mod, target, feature)
49
+ mod.class_eval do
50
+ # Strip out punctuation on predicates or bang methods since
51
+ # e.g. target?_without_feature is not a valid method name.
52
+ aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
53
+ yield(aliased_target, punctuation) if block_given?
54
+
55
+ with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
56
+
57
+ alias_method without_method, target
58
+ alias_method target, with_method
59
+
60
+ case
61
+ when public_method_defined?(without_method)
62
+ public target
63
+ when protected_method_defined?(without_method)
64
+ protected target
65
+ when private_method_defined?(without_method)
66
+ private target
67
+ end
68
+ end
69
+ end
70
+
71
+ # Helper method to coerce a value into a specific class.
72
+ # Raises a TypeError if the coercion fails or the returned value
73
+ # is not of the right class.
74
+ # (from Rubinius)
75
+ def self.coerce_to(obj, cls, meth)
76
+ return obj if obj.kind_of?(cls)
77
+
78
+ begin
79
+ ret = obj.__send__(meth)
80
+ rescue Exception => e
81
+ raise TypeError, "Coercion error: #{obj.inspect}.#{meth} => #{cls} failed:\n" \
82
+ "(#{e.message})"
83
+ end
84
+ raise TypeError, "Coercion error: obj.#{meth} did NOT return a #{cls} (was #{ret.class})" unless ret.kind_of? cls
85
+ ret
86
+ end
87
+
88
+ # Checks for a failed comparison (in which case it throws an ArgumentError)
89
+ # Additionally, it maps any negative value to -1 and any positive value to +1
90
+ # (from Rubinius)
91
+ def self.coerce_to_comparison(a, b, cmp = (a <=> b))
92
+ raise ArgumentError, "comparison of #{a} with #{b} failed" if cmp.nil?
93
+ return 1 if cmp > 0
94
+ return -1 if cmp < 0
95
+ 0
96
+ end
97
+
98
+ # Used internally to make it easy to deal with optional arguments
99
+ # (from Rubinius)
100
+ Undefined = Object.new
101
+
102
+ # A simple class which allows the construction of Enumerator from a block
103
+ class Yielder
104
+ def initialize(&block)
105
+ @main_block = block
106
+ end
107
+
108
+ def each(&block)
109
+ @final_block = block
110
+ @main_block.call(self)
111
+ end
112
+
113
+ def yield(*arg)
114
+ @final_block.yield(*arg)
115
+ end
116
+ end
117
+ end
data/lib/backports.rb CHANGED
@@ -1,15 +1,4 @@
1
- module Kernel
2
- # Standard in ruby 1.9.
3
- def require_relative(relative_feature)
4
- # Adapted from Pragmatic's "Programming Ruby" (since their version was buggy...)
5
- file = caller.first.split(/:\d/,2).first
6
- if /\A\((.*)\)/ =~ file # eval, etc.
7
- raise LoadError, "require_relative is called in #{$1}"
8
- end
9
- require File.expand_path(relative_feature, File.dirname(file))
10
- end unless method_defined? :require_relative
11
- end
12
-
13
- %w(core_ext module kernel array enumerable enumerator string symbol integer numeric fixnum hash proc binding dir io method regexp struct float object_space argf gc env process).each do |lib|
14
- require_relative "backports/#{lib}"
15
- end
1
+ require File.expand_path(File.dirname(__FILE__) + "/backports/tools")
2
+ Backports.require_relative "backports/1.8.7"
3
+ Backports.require_relative "backports/1.9"
4
+ Backports.require_relative "backports/rails"
@@ -16,12 +16,12 @@ class EnumeratorTest < Test::Unit::TestCase
16
16
  context "#new" do
17
17
  should "should accept block" do
18
18
  enum = Enumerator.new do |yielder|
19
- yielder.yield "This cool new syntax is sponsored by"
20
- yielder.yield yielder.class
19
+ yielder.yield "This syntax is"
20
+ yielder.yield "cool!"
21
21
  end
22
22
  assert enum.is_a?(Enumerator)
23
23
  2.times do
24
- assert_equal ["This cool new syntax is sponsored by", Enumerator::Yielder], enum.to_a
24
+ assert_equal ["This syntax is", "cool!"], enum.to_a
25
25
  end
26
26
  end
27
27
  end
data/test/test_helper.rb CHANGED
@@ -2,9 +2,7 @@ require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
4
 
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'backports'
5
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/backports")
8
6
 
9
7
  # class Test::Unit::TestCase
10
8
  # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marcandre-backports
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Marc-Andr\xC3\xA9 Lafortune"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-20 00:00:00 -07:00
12
+ date: 2009-08-31 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,32 +32,49 @@ files:
32
32
  - VERSION.yml
33
33
  - backports.gemspec
34
34
  - lib/backports.rb
35
- - lib/backports/argf.rb
36
- - lib/backports/array.rb
37
- - lib/backports/binding.rb
38
- - lib/backports/core_ext.rb
39
- - lib/backports/dir.rb
40
- - lib/backports/enumerable.rb
41
- - lib/backports/enumerator.rb
42
- - lib/backports/env.rb
43
- - lib/backports/fixnum.rb
44
- - lib/backports/float.rb
45
- - lib/backports/gc.rb
46
- - lib/backports/hash.rb
47
- - lib/backports/integer.rb
48
- - lib/backports/io.rb
49
- - lib/backports/kernel.rb
50
- - lib/backports/method.rb
51
- - lib/backports/module.rb
52
- - lib/backports/numeric.rb
53
- - lib/backports/object_space.rb
54
- - lib/backports/proc.rb
55
- - lib/backports/process.rb
56
- - lib/backports/range.rb
57
- - lib/backports/regexp.rb
58
- - lib/backports/string.rb
59
- - lib/backports/struct.rb
60
- - lib/backports/symbol.rb
35
+ - lib/backports/1.8.7.rb
36
+ - lib/backports/1.8.7/argf.rb
37
+ - lib/backports/1.8.7/array.rb
38
+ - lib/backports/1.8.7/binding.rb
39
+ - lib/backports/1.8.7/dir.rb
40
+ - lib/backports/1.8.7/enumerable.rb
41
+ - lib/backports/1.8.7/enumerator.rb
42
+ - lib/backports/1.8.7/env.rb
43
+ - lib/backports/1.8.7/fixnum.rb
44
+ - lib/backports/1.8.7/float.rb
45
+ - lib/backports/1.8.7/gc.rb
46
+ - lib/backports/1.8.7/hash.rb
47
+ - lib/backports/1.8.7/integer.rb
48
+ - lib/backports/1.8.7/io.rb
49
+ - lib/backports/1.8.7/kernel.rb
50
+ - lib/backports/1.8.7/method.rb
51
+ - lib/backports/1.8.7/module.rb
52
+ - lib/backports/1.8.7/numeric.rb
53
+ - lib/backports/1.8.7/object_space.rb
54
+ - lib/backports/1.8.7/proc.rb
55
+ - lib/backports/1.8.7/process.rb
56
+ - lib/backports/1.8.7/range.rb
57
+ - lib/backports/1.8.7/regexp.rb
58
+ - lib/backports/1.8.7/string.rb
59
+ - lib/backports/1.8.7/struct.rb
60
+ - lib/backports/1.8.7/symbol.rb
61
+ - lib/backports/1.9.rb
62
+ - lib/backports/1.9/array.rb
63
+ - lib/backports/1.9/enumerable.rb
64
+ - lib/backports/1.9/enumerator.rb
65
+ - lib/backports/1.9/hash.rb
66
+ - lib/backports/1.9/integer.rb
67
+ - lib/backports/1.9/kernel.rb
68
+ - lib/backports/1.9/string.rb
69
+ - lib/backports/1.9/symbol.rb
70
+ - lib/backports/rails.rb
71
+ - lib/backports/rails/array.rb
72
+ - lib/backports/rails/enumerable.rb
73
+ - lib/backports/rails/hash.rb
74
+ - lib/backports/rails/kernel.rb
75
+ - lib/backports/rails/module.rb
76
+ - lib/backports/rails/string.rb
77
+ - lib/backports/tools.rb
61
78
  - test/array_test.rb
62
79
  - test/binding_test.rb
63
80
  - test/enumerable_test.rb
@@ -71,9 +88,8 @@ files:
71
88
  - test/string_test.rb
72
89
  - test/symbol_test.rb
73
90
  - test/test_helper.rb
74
- has_rdoc: true
91
+ has_rdoc: false
75
92
  homepage: http://github.com/marcandre/backports
76
- licenses:
77
93
  post_install_message:
78
94
  rdoc_options:
79
95
  - --charset=UTF-8
@@ -100,9 +116,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
116
  requirements: []
101
117
 
102
118
  rubyforge_project: backports
103
- rubygems_version: 1.3.5
119
+ rubygems_version: 1.2.0
104
120
  signing_key:
105
- specification_version: 2
121
+ specification_version: 3
106
122
  summary: Backports or ruby 1.8.7+ & rails for older ruby.
107
123
  test_files:
108
124
  - test/array_test.rb
@@ -1,61 +0,0 @@
1
- # These are non-standard extensions
2
-
3
- class Module
4
- # Metaprogramming utility to make block optional.
5
- # Tests first if block is already optional when given options
6
- def make_block_optional(*methods)
7
- options = methods.extract_options!
8
- methods.each do |selector|
9
- next unless method_defined? selector
10
- unless options.empty?
11
- test_on = options[:test_on] || self.new
12
- next if (test_on.send(selector, *options.fetch(:arg, [])) rescue false)
13
- end
14
-
15
- arity = instance_method(selector).arity
16
- last_arg = []
17
- if arity < 0
18
- last_arg = ["*rest"]
19
- arity = -1-arity
20
- end
21
- arg_sequence = ((0...arity).map{|i| "arg_#{i}"} + last_arg + ["&block"]).join(", ")
22
-
23
- alias_method_chain(selector, :optional_block) do |aliased_target, punctuation|
24
- module_eval <<-end_eval
25
- def #{aliased_target}_with_optional_block#{punctuation}(#{arg_sequence})
26
- return to_enum(:#{aliased_target}_without_optional_block#{punctuation}, #{arg_sequence}) unless block_given?
27
- #{aliased_target}_without_optional_block#{punctuation}(#{arg_sequence})
28
- end
29
- end_eval
30
- end
31
- end
32
- end
33
- end
34
-
35
- module Type
36
- # From Rubinius
37
- class << self
38
- def coerce_to(obj, cls, meth)
39
- return obj if obj.kind_of?(cls)
40
-
41
- begin
42
- ret = obj.__send__(meth)
43
- rescue Exception => e
44
- raise TypeError, "Coercion error: #{obj.inspect}.#{meth} => #{cls} failed:\n" \
45
- "(#{e.message})"
46
- end
47
- raise TypeError, "Coercion error: obj.#{meth} did NOT return a #{cls} (was #{ret.class})" unless ret.kind_of? cls
48
- ret
49
- end unless method_defined? :coerce_to
50
- end
51
-
52
- def self.coerce_to_comparison(a, b, cmp = (a <=> b))
53
- raise ArgumentError, "comparison of #{a} with #{b} failed" if cmp.nil?
54
- return 1 if cmp > 0
55
- return -1 if cmp < 0
56
- 0
57
- end unless method_defined? :coerce_to_comparison
58
- end
59
-
60
- # From Rubinius
61
- Undefined = Object.new unless Kernel.const_defined? :Undefined
data/lib/backports/dir.rb DELETED
@@ -1,7 +0,0 @@
1
- class Dir
2
- make_block_optional :each, :test_on => Dir.new(".")
3
- class << self
4
- make_block_optional :foreach, :test_on => Dir, :arg => "."
5
- end
6
- end
7
-
@@ -1,43 +0,0 @@
1
- class Enumerator
2
- alias_method :with_object, :each_with_object unless method_defined? :with_object
3
-
4
- def next
5
- require 'generator'
6
- @generator ||= Generator.new(self)
7
- raise StopIteration unless @generator.next?
8
- @generator.next
9
- end unless method_defined? :next
10
-
11
- def rewind
12
- @object.rewind if @object.respond_to? :rewind
13
- require 'generator'
14
- @generator ||= Generator.new(self)
15
- @generator.rewind
16
- self
17
- end unless method_defined? :rewind
18
-
19
- # new with block, standard in Ruby 1.9
20
- unless (self.new{} rescue false)
21
- class Yielder
22
- def initialize(&block)
23
- @main_block = block
24
- end
25
-
26
- def each(&block)
27
- @final_block = block
28
- @main_block.call(self)
29
- end
30
-
31
- def yield(*arg)
32
- @final_block.yield(*arg)
33
- end
34
- end
35
-
36
- def initialize_with_optional_block(*arg, &block)
37
- @object = arg.first
38
- return initialize_without_optional_block(*arg, &nil) unless arg.empty? # Ruby 1.9 apparently ignores the block if any argument is present
39
- initialize_without_optional_block(Yielder.new(&block))
40
- end
41
- alias_method_chain :initialize, :optional_block
42
- end
43
- end
data/lib/backports/env.rb DELETED
@@ -1,3 +0,0 @@
1
- class << ENV
2
- make_block_optional :delete_if, :each, :each_key, :each_pair, :each_value, :reject!, :select, :test_on => ENV
3
- end
@@ -1,11 +0,0 @@
1
- class Fixnum
2
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
3
- def div(n)
4
- (self / n).to_i
5
- end unless method_defined? :div
6
-
7
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
8
- def fdiv(n)
9
- to_f / n
10
- end unless method_defined? :fdiv
11
- end
@@ -1,4 +0,0 @@
1
- class Fixnum
2
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
3
- alias_method :fdiv, :/ unless method_defined? :fdiv
4
- end
@@ -1,64 +0,0 @@
1
- class Hash
2
- # New Ruby 1.8.7+ constructor -- not documented, see redmine # 1385
3
- # <tt>Hash[[[:foo, :bar],[:hello, "world"]]] ==> {:foo => :bar, :hello => "world"}</tt>
4
- class << self
5
- alias_method :original_constructor, :[]
6
- def [](*args)
7
- return original_constructor(*args) unless args.length == 1 && args.first.is_a?(Array)
8
- returning({}) do |h|
9
- args.first.each do |arr|
10
- next unless arr.respond_to? :to_ary
11
- arr = arr.to_ary
12
- next unless (1..2).include? arr.size
13
- h[arr.at(0)] = arr.at(1)
14
- end
15
- end
16
- end unless (Hash[[[:test, :test]]] rescue false)
17
-
18
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]
19
- def try_convert(x)
20
- return nil unless x.respond_to? :to_hash
21
- x.to_hash
22
- end unless method_defined? :to_hash
23
- end
24
-
25
- make_block_optional :delete_if, :each, :each_key, :each_pair, :each_value, :reject, :reject!, :select, :test_on => {:hello => "world!"}
26
-
27
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]
28
- def default_proc=(proc)
29
- replace(Hash.new(&Type.coerce_to(proc, Proc, :to_proc)).merge!(self))
30
- end unless method_defined? :default_proc=
31
-
32
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]
33
- alias_method :key, :index unless method_defined? :key
34
-
35
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
36
- def reverse_merge(other_hash)
37
- other_hash.merge(self)
38
- end
39
-
40
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
41
- def reverse_merge!(other_hash)
42
- replace(reverse_merge(other_hash))
43
- end
44
-
45
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
46
- def symbolize_keys
47
- Hash[map{|key,value| [(key.to_sym rescue key) || key, value] }]
48
- end unless method_defined? :symbolize_keys
49
-
50
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
51
- def symbolize_keys!
52
- self.replace(self.symbolize_keys)
53
- end unless method_defined? :symbolize_keys!
54
-
55
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
56
- def stringify_keys
57
- Hash[map{|key,value| [key.to_s, value] }]
58
- end unless method_defined? :stringify_keys
59
-
60
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
61
- def stringify_keys!
62
- self.replace(self.stringify_keys)
63
- end unless method_defined? :stringify_keys!
64
- end
@@ -1,25 +0,0 @@
1
- class Integer
2
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
3
- def even?
4
- self[0].zero?
5
- end unless method_defined? :even?
6
-
7
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
8
- def odd?
9
- !even?
10
- end unless method_defined? :odd?
11
-
12
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
13
- def ord
14
- self
15
- end unless method_defined? :ord
16
-
17
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
18
- def pred
19
- self - 1
20
- end unless method_defined? :pred
21
-
22
- alias_method :magnitude, :abs unless method_defined? :magnitude
23
-
24
- make_block_optional :downto, :times, :upto, :test_on => 42, :arg => 42
25
- end
@@ -1,55 +0,0 @@
1
- require 'enumerator'
2
- # Must be defined outside of Kernel for jruby, see http://jira.codehaus.org/browse/JRUBY-3609
3
- Enumerator = Enumerable::Enumerator unless Kernel.const_defined? :Enumerator # Standard in ruby 1.9
4
-
5
- module Kernel
6
-
7
- def __callee__
8
- caller(1).first[/`(.*)'/,1].try(:to_sym)
9
- end unless (__callee__ || true rescue false)
10
-
11
- alias_method :__method__, :__callee__ unless (__method__ || true rescue false)
12
-
13
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
14
- def define_singleton_method(*args, &block)
15
- class << self
16
- self
17
- end.send(:define_method, *args, &block)
18
- end unless method_defined? :define_singleton_method
19
-
20
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
21
- def instance_exec(*arg, &block)
22
- define_singleton_method(:"temporary method for instance_exec", &block)
23
- send(:"temporary method for instance_exec", *arg)
24
- end unless method_defined? :instance_exec
25
-
26
- # Loop. Standard in ruby 1.8.7. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
27
- unless const_defined? :StopIteration
28
- class StopIteration < IndexError; end
29
-
30
- def loop_with_stop_iteration(&block)
31
- loop_without_stop_iteration(&block)
32
- rescue StopIteration
33
- # ignore silently
34
- end
35
- alias_method_chain :loop, :stop_iteration
36
- end
37
-
38
- # Standard in ruby 1.8.7. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
39
- def tap
40
- yield self
41
- self
42
- end unless method_defined? :tap
43
-
44
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/Object.html]
45
- def try(method_id, *args, &block)
46
- send(method_id, *args, &block) unless self.nil? #todo: check new def
47
- end unless method_defined? :try
48
-
49
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/Object.html]
50
- def returning(obj)
51
- yield obj
52
- obj
53
- end unless method_defined? :returning
54
-
55
- end
@@ -1,30 +0,0 @@
1
- class Module
2
- # Standard in rails... See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Module.html]
3
- def alias_method_chain(target, feature)
4
- # Strip out punctuation on predicates or bang methods since
5
- # e.g. target?_without_feature is not a valid method name.
6
- aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
7
- yield(aliased_target, punctuation) if block_given?
8
-
9
- with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
10
-
11
- alias_method without_method, target
12
- alias_method target, with_method
13
-
14
- case
15
- when public_method_defined?(without_method)
16
- public target
17
- when protected_method_defined?(without_method)
18
- protected target
19
- when private_method_defined?(without_method)
20
- private target
21
- end
22
- end unless method_defined? :alias_method_chain
23
-
24
- # Can't use alias_method here because of jruby (see http://jira.codehaus.org/browse/JRUBY-2435 )
25
- def module_exec(*arg, &block)
26
- instance_exec(*arg, &block)
27
- end unless method_defined? :module_exec
28
- alias_method :class_exec, :module_exec unless method_defined? :class_exec
29
-
30
- end
@@ -1,3 +0,0 @@
1
- class Numeric
2
- make_block_optional :step, :test_on => 42, :arg => [100, 6]
3
- end
@@ -1,5 +0,0 @@
1
- module ObjectSpace
2
- module_eval do
3
- make_block_optional :each_object, :test_on => ObjectSpace
4
- end
5
- end
@@ -1,4 +0,0 @@
1
- class Range
2
- make_block_optional :each, :test_on => 69..666
3
- make_block_optional :step, :test_on => 69..666, :arg => 42
4
- end