Comments (11)
Could you try it without "Bond activated"?
from awesome_print.
timcharper@timcharper:~/projects $ irb -f
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'ap'
=> true
irb(main):003:0> ap String.methods
LocalJumpError: no block given
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:264:in `times'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:264:in `method_tuple'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:178:in `methods_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:176:in `map'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:176:in `methods_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:54:in `awesome_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:165:in `send'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:165:in `awesome'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:10:in `send'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:10:in `ai'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:15:in `ap'
from (irb):3
from awesome_print.
$ ruby -v
from awesome_print.
timcharper@timcharper:~ $ ruby -v
ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0]
from awesome_print.
Could you try to replace:
args = method.arity.abs.times.map { |i| "arg#{i+1}" }
with
args = (1..method.arity.abs).map { |i| "arg#{i+1}" }
(line 264 in /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb)
from awesome_print.
That made progress! Looks like Method#name was introduced in ruby 1.8.7. It's easy enough to backport, though:
module Method::BackwardCompatibility
def name
inspect.scan(/#\<.+[#.](.+)\>/).flatten.first
end
end
Method.send :include, Method::BackwardCompatibility
UnboundMethod.send :include, Method::BackwardCompatibility
Output from IRB:
timcharper@timcharper:~ $ irb -frper:~ $
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'ap'
=> true
irb(main):003:0> ap Fixnum.methods
NoMethodError: undefined method `name' for #<Method: Class(Module)#<>
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:272:in `method_tuple'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:178:in `methods_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:176:in `map'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:176:in `methods_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:54:in `awesome_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:165:in `send'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:165:in `awesome'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:10:in `send'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:10:in `ai'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:15:in `ap'
from (irb):3
irb(main):004:0> module Method::BackwardCompatibility; def name; inspect.scan(/#\<.+[#.](.+)\>/).flatten.first; end; end
=> nil
irb(main):005:0> Method.send(:include, Method::BackwardCompatibility)
=> Method
irb(main):006:0> ap Fixnum.methods
[
[ 0] <(arg2) Class (Module)
[ 1] <=(arg2) Class (Module)
[ 2] <=>(arg2) Class (Module)
[ 3] ==(arg2) Class (Module)
[ 4] ===(arg2) Class (Module)
[ 5] =~(arg2) Class (Kernel)
[ 6] >(arg2) Class (Module)
[ 7] >=(arg2) Class (Module)
[ 8] __id__() Class (Kernel)
[ 9] __send__(*arg2) Class (Kernel)
[10] ai(*arg2) Class (Kernel)
[11] allocate() Class
[12] ancestors() Class (Module)
[13] autoload(arg2, arg3) Class (Module)
[14] autoload?(arg2) Class (Module)
[15] awesome_inspect(*arg2) Class (Kernel)
[16] awesome_print(arg2, *arg3) Class (Kernel)
[17] class() Class (Kernel)
[18] class_eval(*arg2) Class (Module)
[19] class_variable_defined?(arg2) Class (Module)
[20] class_variables() Class (Module)
[21] clone() Class (Kernel)
[22] const_defined?(arg2) Class (Module)
[23] const_get(arg2) Class (Module)
[24] const_missing(arg2) Class (Module)
[25] const_set(arg2, arg3) Class (Module)
[26] constants() Class (Module)
[27] display(*arg2) Class (Kernel)
[28] dup() Class (Kernel)
[29] eql?(arg2) Class (Kernel)
[30] equal?(arg2) Class (Kernel)
[31] extend(*arg2) Class (Kernel)
[32] freeze() Class (Module)
[33] frozen?() Class (Kernel)
[34] hash() Class (Kernel)
[35] id() Class (Kernel)
[36] include?(arg2) Class (Module)
[37] included_modules() Class (Module)
[38] induced_from(arg2) Fixnum
[39] inspect() Class (Kernel)
[40] instance_eval(*arg2) Class (Kernel)
[41] instance_method(arg2) Class (Module)
[42] instance_methods(*arg2) Class
[43] instance_of?(arg2) Class (Kernel)
[44] instance_variable_defined?(arg2) Class (Kernel)
[45] instance_variable_get(arg2) Class (Kernel)
[46] instance_variable_set(arg2, arg3) Class (Kernel)
[47] instance_variables() Class (Kernel)
[48] is_a?(arg2) Class (Kernel)
[49] kind_of?(arg2) Class (Kernel)
[50] method(arg2) Class (Kernel)
[51] method_defined?(arg2) Class (Module)
[52] methods(*arg2) Class (Object)
[53] module_eval(*arg2) Class (Module)
[54] name() Class (Module)
[55] nil?() Class (Kernel)
[56] object_id() Class (Kernel)
[57] original_instance_methods(*arg2) Class (Module)
[58] original_methods(*arg2) Class (Kernel)
[59] original_private_instance_methods(*arg2) Class (Module)
[60] original_private_methods(*arg2) Class (Kernel)
[61] original_protected_instance_methods(*arg2) Class (Module)
[62] original_protected_methods(*arg2) Class (Kernel)
[63] original_public_instance_methods(*arg2) Class (Module)
[64] original_public_methods(*arg2) Class (Kernel)
[65] original_singleton_methods(*arg2) Class (Kernel)
[66] private_class_method(*arg2) Class (Module)
[67] private_instance_methods(*arg2) Class
[68] private_method_defined?(arg2) Class (Module)
[69] private_methods(*arg2) Class (Object)
[70] protected_instance_methods(*arg2) Class
[71] protected_method_defined?(arg2) Class (Module)
[72] protected_methods(*arg2) Class (Object)
[73] public_class_method(*arg2) Class (Module)
[74] public_instance_methods(*arg2) Class
[75] public_method_defined?(arg2) Class (Module)
[76] public_methods(*arg2) Class (Object)
[77] respond_to?(*arg2) Class (Kernel)
[78] send(*arg2) Class (Kernel)
[79] singleton_methods(*arg2) Class (Object)
[80] superclass() Class
[81] taguri() Class (Object)
[82] taguri=(arg2) Class (Object)
[83] taint() Class (Kernel)
[84] tainted?() Class (Kernel)
[85] to_a() Class (Kernel)
[86] to_s() Class (Module)
[87] to_yaml(*arg2) Class
[88] to_yaml_properties() Class (Object)
[89] to_yaml_style() Class (Object)
[90] type() Class (Kernel)
[91] untaint() Class (Kernel)
[92] yaml_as(arg2, *arg3) Class (Module)
[93] yaml_tag_class_name() Class (Module)
[94] yaml_tag_read_class(arg2) Class (Module)
[95] yaml_tag_subclasses?() Fixnum (Integer)
]
=> nil
irb(main):007:0> ap Fixnum.instance_methods
NoMethodError: undefined method `name' for #<UnboundMethod: Fixnum#%>
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:272:in `method_tuple'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:180:in `methods_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:176:in `map'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:176:in `methods_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:54:in `awesome_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:165:in `send'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:165:in `awesome'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:10:in `send'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:10:in `ai'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:15:in `ap'
from (irb):7
irb(main):008:0> UnboundMethod.send(:include, Method::BackwardCompatibility)
=> UnboundMethod
irb(main):009:0> ap Fixnum.instance_methods
[
[ 0] %(arg2) Fixnum (unbound)
[ 1] &(arg2) Fixnum (unbound)
[ 2] *(arg2) Fixnum (unbound)
[ 3] **(arg2) Fixnum (unbound)
[ 4] +(arg2) Fixnum (unbound)
[ 5] +@() Fixnum (Numeric) (unbound)
[ 6] -(arg2) Fixnum (unbound)
[ 7] -@() Fixnum (unbound)
[ 8] /(arg2) Fixnum (unbound)
[ 9] <(arg2) Class (Module)
[ 10] <<(arg2) Fixnum (unbound)
[ 11] <=(arg2) Class (Module)
[ 12] <=>(arg2) Class (Module)
[ 13] ==(arg2) Class (Module)
[ 14] ===(arg2) Class (Module)
[ 15] =~(arg2) Class (Kernel)
[ 16] >(arg2) Class (Module)
[ 17] >=(arg2) Class (Module)
[ 18] >>(arg2) Fixnum (unbound)
[ 19] [](arg2) Fixnum (unbound)
[ 20] ^(arg2) Fixnum (unbound)
[ 21] __id__() Class (Kernel)
[ 22] __send__(*arg2) Class (Kernel)
[ 23] abs() Fixnum (unbound)
[ 24] ai(*arg2) Class (Kernel)
[ 25] awesome_inspect(*arg2) Class (Kernel)
[ 26] awesome_print(arg2, *arg3) Class (Kernel)
[ 27] between?(arg2, arg3) Fixnum (Comparable) (unbound)
[ 28] ceil() Fixnum (Integer) (unbound)
[ 29] chr() Fixnum (Integer) (unbound)
[ 30] class() Class (Kernel)
[ 31] clone() Class (Kernel)
[ 32] coerce(arg2) Fixnum (Numeric) (unbound)
[ 33] denominator() Fixnum (Integer) (unbound)
[ 34] display(*arg2) Class (Kernel)
[ 35] div(arg2) Fixnum (unbound)
[ 36] divmod(arg2) Fixnum (unbound)
[ 37] downto(arg2) Fixnum (Integer) (unbound)
[ 38] dup() Class (Kernel)
[ 39] eql?(arg2) Class (Kernel)
[ 40] equal?(arg2) Class (Kernel)
[ 41] extend(*arg2) Class (Kernel)
[ 42] floor() Fixnum (Integer) (unbound)
[ 43] freeze() Class (Module)
[ 44] frozen?() Class (Kernel)
[ 45] gcd(arg2) Fixnum (Integer) (unbound)
[ 46] gcdlcm(arg2) Fixnum (Integer) (unbound)
[ 47] hash() Class (Kernel)
[ 48] id() Class (Kernel)
[ 49] id2name() Fixnum (unbound)
[ 50] inspect() Class (Kernel)
[ 51] instance_eval(*arg2) Class (Kernel)
[ 52] instance_of?(arg2) Class (Kernel)
[ 53] instance_variable_defined?(arg2) Class (Kernel)
[ 54] instance_variable_get(arg2) Class (Kernel)
[ 55] instance_variable_set(arg2, arg3) Class (Kernel)
[ 56] instance_variables() Class (Kernel)
[ 57] integer?() Fixnum (Integer) (unbound)
[ 58] is_a?(arg2) Class (Kernel)
[ 59] kind_of?(arg2) Class (Kernel)
[ 60] lcm(arg2) Fixnum (Integer) (unbound)
[ 61] method(arg2) Class (Kernel)
[ 62] methods(*arg2) Class (Object)
[ 63] modulo(arg2) Fixnum (unbound)
[ 64] next() Fixnum (Integer) (unbound)
[ 65] nil?() Class (Kernel)
[ 66] nonzero?() Fixnum (Numeric) (unbound)
[ 67] numerator() Fixnum (Integer) (unbound)
[ 68] object_id() Class (Kernel)
[ 69] original_methods(*arg2) Class (Kernel)
[ 70] original_private_methods(*arg2) Class (Kernel)
[ 71] original_protected_methods(*arg2) Class (Kernel)
[ 72] original_public_methods(*arg2) Class (Kernel)
[ 73] original_singleton_methods(*arg2) Class (Kernel)
[ 74] power!(arg2) Fixnum (unbound)
[ 75] prec(arg2) Fixnum (Precision) (unbound)
[ 76] prec_f() Fixnum (Precision) (unbound)
[ 77] prec_i() Fixnum (Precision) (unbound)
[ 78] private_methods(*arg2) Class (Object)
[ 79] protected_methods(*arg2) Class (Object)
[ 80] public_methods(*arg2) Class (Object)
[ 81] quo(arg2) Fixnum (unbound)
[ 82] rdiv(arg2) Fixnum (unbound)
[ 83] remainder(arg2) Fixnum (Numeric) (unbound)
[ 84] respond_to?(*arg2) Class (Kernel)
[ 85] round() Fixnum (Integer) (unbound)
[ 86] rpower(arg2) Fixnum (unbound)
[ 87] send(*arg2) Class (Kernel)
[ 88] singleton_method_added(arg2) Class (Kernel)
[ 89] singleton_methods(*arg2) Class (Object)
[ 90] size() Fixnum (unbound)
[ 91] step(*arg2) Fixnum (Numeric) (unbound)
[ 92] succ() Fixnum (Integer) (unbound)
[ 93] taguri() Class (Object)
[ 94] taguri=(arg2) Class (Object)
[ 95] taint() Class (Kernel)
[ 96] tainted?() Class (Kernel)
[ 97] times() Fixnum (Integer) (unbound)
[ 98] to_a() Class (Kernel)
[ 99] to_f() Fixnum (unbound)
[100] to_i() Fixnum (Integer) (unbound)
[101] to_int() Fixnum (Integer) (unbound)
[102] to_r() Fixnum (Integer) (unbound)
[103] to_s() Class (Module)
[104] to_sym() Fixnum (unbound)
[105] to_yaml(*arg2) Class
[106] to_yaml_properties() Class (Object)
[107] to_yaml_style() Class (Object)
[108] truncate() Fixnum (Integer) (unbound)
[109] type() Class (Kernel)
[110] untaint() Class (Kernel)
[111] upto(arg2) Fixnum (Integer) (unbound)
[112] zero?() Fixnum (unbound)
[113] |(arg2) Fixnum (unbound)
[114] ~() Fixnum (unbound)
]
=> nil
irb(main):010:0>
from awesome_print.
I'm excited to use this! Thanks for putting it together. Outputting methods and grokking the output has always been a chore in the past.
from awesome_print.
Cool, have you tried:
[].methods - Object.methods
Also, check out if this works with Ruby 1.8.6:
[].methods.grep(/^s/)
from awesome_print.
Hmm... just noticed the arguments start with arg2, so the correct patch is:
args = (1..method.arity.abs).map { |i| "arg#{i}" }
from awesome_print.
re: ^^
Both of those work in 1.8.6
Duly noted on the patch update :) thanks!
from awesome_print.
Just released 0.3.1 with all the fixes above. Thanks, Tim!
from awesome_print.
Related Issues (20)
- Proc.new is deprecated HOT 5
- irb: ArgumentError (wrong number of arguments (given 1, expected 0)) HOT 2
- Output of non-empty Hash object fails when using Ruby 3.0 HOT 1
- 1.9 release HOT 12
- Array#uniq is not working on pry with `AwesomePrint.pry!` HOT 5
- Ruby 2.7.0 compatibility HOT 2
- problem with rails and ruby 3.0.0 HOT 2
- ArgumentError (wrong number of arguments (given 1, expected 0)) HOT 4
- undefined method `marshal_dump` for `ActiveModel::Errors` HOT 6
- Getting FrozenError (can't modify frozen String: "false") after upgrading to Ruby 2.7.3 using awesome_print (1.9.2) HOT 5
- Plain Ruby Objects are not formatted properly HOT 2
- Hi, can I put `.aprc` under ~/.config/awesome_print/aprc?
- `.pry!` does nothing in rails console
- Don't override/monkey patch `String` class HOT 3
- Provide a way of specifying custom formatting on user-created classes/objects HOT 2
- object_id option not operating as expected
- Maintained fork: amazing-print/amazing_print
- Pretty print object as executable code
- ap.awesome_sequel_dataset(ds) Arguments Error
- ActiveRecord methods with `ap` displays nothing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awesome_print.