Kernel#y

Two suggestions for Kernel#y:

  1. Make it private, like Kernel#p.

  2. Let it take multiple args, like Kernel#p, something like:

y 1,2,3
— 1
— 2
— 3
=> nil

Anyone see any sense in these?

I could add

  1. Tell everyone about it because it’s very useful :slight_smile:

“Joel VanderWerf” vjoel@PATH.Berkeley.EDU

  1. Tell everyone about it because it’s very useful :slight_smile:

Yes, please tell us more. What is it ?
Thanks,
– shanko

do tell. ‘y’ for yaml?

-a

···

On Sun, 14 Mar 2004, Joel VanderWerf wrote:

Two suggestions for Kernel#y:

  1. Make it private, like Kernel#p.

  2. Let it take multiple args, like Kernel#p, something like:

y 1,2,3
— 1
— 2
— 3
=> nil

Anyone see any sense in these?

I could add

  1. Tell everyone about it because it’s very useful :slight_smile:

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
===============================================================================

Ara.T.Howard wrote:

Two suggestions for Kernel#y:

  1. Make it private, like Kernel#p.

  2. Let it take multiple args, like Kernel#p, something like:

y 1,2,3
— 1
— 2
— 3
=> nil

Anyone see any sense in these?

I could add

  1. Tell everyone about it because it’s very useful :slight_smile:

do tell. ‘y’ for yaml?

Create a bunch of stuff:

ahash = {:a => 1, ‘BB’ => 2, 7 => ‘seven’, ‘d’ => 10}
astring = RUBY_VERSION + ’ ’ + RELEASE_DATE
afloat = Math::PI
anarray = [‘c’, 111, Exception.new(‘Oops’)]

Bunch it more:

anarray.push(ahash).push(astring).push(afloat)

p anarray # for comparison
puts ‘.’*107, ‘’

See what yaml’s y shows

require ‘yaml’ # <-------------------------#
y anarray

["c", 111, #, {"BB"=>2, "d"=>10, 7=>"seven", :a=>1}, "1.8.0 2003-08-30", 3.14159265358979] ............................................................................................................
···

On Sun, 14 Mar 2004, Joel VanderWerf wrote:


  • c
  • 111
  • !ruby/exception:Exception
    message: Oops
  • BB: 2
    d: 10
    7: seven
    !ruby/sym a: 1
  • 1.8.0 2003-08-30
  • 3.14159265358979

daz

wow. very, very cool.

definitely should be changed to

def y(*args)
args.each{|a| super a}
end

though.

-a

···

On Sun, 14 Mar 2004, daz wrote:

Ara.T.Howard wrote:

On Sun, 14 Mar 2004, Joel VanderWerf wrote:

Two suggestions for Kernel#y:

  1. Make it private, like Kernel#p.

  2. Let it take multiple args, like Kernel#p, something like:

y 1,2,3
— 1
— 2
— 3
=> nil

Anyone see any sense in these?

I could add

  1. Tell everyone about it because it’s very useful :slight_smile:

do tell. ‘y’ for yaml?

Create a bunch of stuff:

ahash = {:a => 1, ‘BB’ => 2, 7 => ‘seven’, ‘d’ => 10}
astring = RUBY_VERSION + ’ ’ + RELEASE_DATE
afloat = Math::PI
anarray = [‘c’, 111, Exception.new(‘Oops’)]

Bunch it more:

anarray.push(ahash).push(astring).push(afloat)

p anarray # for comparison
puts ‘.’*107, ‘’

See what yaml’s y shows

require ‘yaml’ # <-------------------------#
y anarray

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
===============================================================================

Two suggestions for Kernel#y:

  1. Make it private, like Kernel#p.

ok, done.

  1. Let it take multiple args, like Kernel#p, something like:

y 1,2,3
— 1
— 2
— 3
=> nil

and, yes, as well. very good, thank you. checked into syck cvs now.
ruby 1.9 branch shortly.

Ara.T.Howard wrote:

definitely should be changed to

def y(*args)
args.each{|a| super a}
end

close, instead let’s output multiple inputs as a YAML stream, with each
having their own document:

module Kernel
def y( *x )
puts( if x.length == 1
YAML::dump( *x )
else
YAML::dump_stream( *x )
end )
end
private :y
end

works the same, but allows Kernel#y to dump headless documents if only
one input is sent.

great suggestions, cool, cool…

_why

···

On Sun, 14 Mar 2004, Joel VanderWerf wrote:

“Ara.T.Howard” ahoward@fattire.ngdc.noaa.gov schrieb im Newsbeitrag
news:Pine.LNX.4.44.0403140908141.6230-100000@fattire.ngdc.noaa.gov

Create a bunch of stuff:

ahash = {:a => 1, ‘BB’ => 2, 7 => ‘seven’, ‘d’ => 10}
astring = RUBY_VERSION + ’ ’ + RELEASE_DATE
afloat = Math::PI
anarray = [‘c’, 111, Exception.new(‘Oops’)]

Bunch it more:

anarray.push(ahash).push(astring).push(afloat)

p anarray # for comparison
puts ‘.’*107, ‘’

See what yaml’s y shows

require ‘yaml’ # <-------------------------#
y anarray

wow. very, very cool.

Hm. Where’s the difference between “puts obj.to_yaml” and “y obj” apart from
less typing?

robert

Robert Klemme wrote:

Hm. Where’s the difference between “puts obj.to_yaml” and “y obj” apart from
less typing?

Actually, that’s pretty much the definition from yaml.rb:

module Kernel
def y( x )
puts x.to_yaml
end
end

Kernel#y and Object#to_yaml are analogous to Kernel#p and
Object#inspect. Both #y and #p are convenient for debugging and irb. And
there’s also #pp, which is nice to have, too.