mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Ruby 1.8.6 compatibility fixes (undefined Method#name and Fixnum#times without block)
This commit is contained in:
parent
bbefc738a5
commit
fcbd18377a
3 changed files with 29 additions and 11 deletions
17
lib/ap.rb
17
lib/ap.rb
|
@ -3,16 +3,13 @@
|
|||
# Awesome Print is freely distributable under the terms of MIT license.
|
||||
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
||||
#------------------------------------------------------------------------------
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/array"
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/string"
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/object"
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/class"
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/kernel"
|
||||
%w(array string method object class kernel).each do |file|
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/#{file}"
|
||||
end
|
||||
|
||||
require File.dirname(__FILE__) + "/ap/awesome_print"
|
||||
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/logger" if defined?(::Logger) or defined?(::ActiveSupport::BufferedLogger)
|
||||
|
||||
require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(::ActionView)
|
||||
require File.dirname(__FILE__) + "/ap/mixin/active_record" if defined?(::ActiveRecord)
|
||||
require File.dirname(__FILE__) + "/ap/core_ext/logger" if defined?(::Logger) or defined?(::ActiveSupport::BufferedLogger)
|
||||
require File.dirname(__FILE__) + "/ap/mixin/action_view" if defined?(::ActionView)
|
||||
require File.dirname(__FILE__) + "/ap/mixin/active_record" if defined?(::ActiveRecord)
|
||||
require File.dirname(__FILE__) + "/ap/mixin/active_support" if defined?(::ActiveSupport)
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ class AwesomePrint
|
|||
end
|
||||
end
|
||||
else # See http://ruby-doc.org/core/classes/Method.html#M001902
|
||||
args = method.arity.abs.times.map { |i| "arg#{i+1}" }
|
||||
args = (1..method.arity.abs).map { |i| "arg#{i}" }
|
||||
args[-1] = "*#{args[-1]}" if method.arity < 0
|
||||
end
|
||||
|
||||
|
|
21
lib/ap/core_ext/method.rb
Normal file
21
lib/ap/core_ext/method.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (c) 2010 Michael Dvorkin
|
||||
#
|
||||
# Awesome Print is freely distributable under the terms of MIT license.
|
||||
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
||||
#------------------------------------------------------------------------------
|
||||
#
|
||||
# Method#name was intorduced in Ruby 1.8.7 so we define it here as necessary.
|
||||
#
|
||||
unless nil.method(:class).respond_to?(:name)
|
||||
class Method
|
||||
def name
|
||||
inspect.split(/[#.>]/)[-1]
|
||||
end
|
||||
end
|
||||
|
||||
class UnboundMethod
|
||||
def name
|
||||
inspect.split(/[#.>]/)[-1]
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue