--bjuZg6miEcdLYP6q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Daniel Carrera (dcarrera / math.umd.edu) wrote:

> I didn't think of that.  I just wrote this one-line script:
> ----------
> #!/bin/sh
> # File name: methods
>=20
> ruby -e 'puts '$1'.new.methods.sort - Object.new.methods.sort' | less
> ----------
>=20
> So I can just type "methods String" on a terminal.

No longer a one-liner, but value-add.  For bonus points,
allow specification of private, protected, singleton, etc methods.

#!/usr/bin/env ruby -w
# Print unique methods and their arity
#
# Can also do ruby -r <library> methods <library classname>

require 'open3'

obj =3D eval(ARGV.shift).new

methods =3D obj.methods.sort - Object.new.methods.sort

methods.collect! do |meth|
  "#{meth}: #{obj.method(meth).arity} arguments"
end

IO.popen('less', 'w') do |less|
  less.puts "Methods for #{obj.class}"
  less.puts methods.join($/)
end

--=20
Eric Hodel - drbrain / segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04


--bjuZg6miEcdLYP6q
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+f6OaMypVHHlsnwQRAjx2AKDnyiFvu8IyUMSXJN2warhQHOLQ5gCgyBIw
4zhqEy4tMQhLPjXY5edQA/A=
=KpLj
-----END PGP SIGNATURE-----

--bjuZg6miEcdLYP6q--

Daniel Carrera (dcarrera / math.umd.edu) wrote:

> I didn't think of that.  I just wrote this one-line script:
> ----------
> #!/bin/sh
> # File name: methods
>=20
> ruby -e 'puts '$1'.new.methods.sort - Object.new.methods.sort' | less
> ----------
>=20
> So I can just type "methods String" on a terminal.

No longer a one-liner, but value-add.  For bonus points,
allow specification of private, protected, singleton, etc methods.

#!/usr/bin/env ruby -w
# Print unique methods and their arity
#
# Can also do ruby -r <library> methods <library classname>

require 'open3'

obj =3D eval(ARGV.shift).new

methods =3D obj.methods.sort - Object.new.methods.sort

methods.collect! do |meth|
  "#{meth}: #{obj.method(meth).arity} arguments"
end

IO.popen('less', 'w') do |less|
  less.puts "Methods for #{obj.class}"
  less.puts methods.join($/)
end

--=20
Eric Hodel - drbrain / segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+f6OaMypVHHlsnwQRAjx2AKDnyiFvu8IyUMSXJN2warhQHOLQ5gCgyBIw
4zhqEy4tMQhLPjXY5edQA/A=
=KpLj
-----END PGP SIGNATURE-----