# Kernel#y

**URL:** <https://rubytalk.org/t/kernel-y/10554>\
**Category:** ruby-talk\
**Created:** [14 March 2004 06:10 UTC](https://rubytalk.org/t/kernel-y/10554 "2004-03-14T06:10:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [14 March 2004 06:10 UTC](https://rubytalk.org/t/kernel-y/10554/1 "2004-03-14T06:10:14Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Shashank\_Date2](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@Shashank\_Date2](https://rubytalk.org/u/Shashank_Date2)\
**Post date:** [14 March 2004 13:14 UTC](https://rubytalk.org/t/kernel-y/10554/2 "2004-03-14T13:14:35Z")

</div>

“Joel VanderWerf” [vjoel@PATH.Berkeley.EDU](mailto:vjoel@PATH.Berkeley.EDU)

> 1. Tell everyone about it because it’s very useful 🙂

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

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Ara.T.Howard](https://rubytalk.org/u/Ara.T.Howard)\
**Post date:** [14 March 2004 14:44 UTC](https://rubytalk.org/t/kernel-y/10554/3 "2004-03-14T14:44:36Z")

</div>

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 🙂
> 
> # –
> 
> > 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](http://www.ngdc.noaa.gov/stp/)  
> > TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done  
> > ===============================================================================

---

<div class="post-metadata">

**Author:** ![daz](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@daz](https://rubytalk.org/u/daz)\
**Post date:** [14 March 2004 15:59 UTC](https://rubytalk.org/t/kernel-y/10554/4 "2004-03-14T15:59:36Z")

</div>

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 🙂
> 
> 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

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@Ara.T.Howard](https://rubytalk.org/u/Ara.T.Howard)\
**Post date:** [14 March 2004 16:24 UTC](https://rubytalk.org/t/kernel-y/10554/5 "2004-03-14T16:24:35Z")

</div>

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 🙂
> > > 
> > > 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](http://www.ngdc.noaa.gov/stp/)  
> > TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done  
> > ===============================================================================

---

<div class="post-metadata">

**Author:** ![why\_the\_lucky\_stiff1](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@why\_the\_lucky\_stiff1](https://rubytalk.org/u/why_the_lucky_stiff1)\
**Post date:** [14 March 2004 18:42 UTC](https://rubytalk.org/t/kernel-y/10554/6 "2004-03-14T18:42:08Z")

</div>

> 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:

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [14 March 2004 18:49 UTC](https://rubytalk.org/t/kernel-y/10554/7 "2004-03-14T18:49:35Z")

</div>

“Ara.T.Howard” [ahoward@fattire.ngdc.noaa.gov](mailto:ahoward@fattire.ngdc.noaa.gov) schrieb im Newsbeitrag  
[news:Pine.LNX.4.44.0403140908141.6230-100000@fattire.ngdc.noaa.gov](mailto: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

```

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [14 March 2004 19:59 UTC](https://rubytalk.org/t/kernel-y/10554/8 "2004-03-14T19:59:04Z")

</div>

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.
