From: Ryan Tarpine Date: 2001-09-11T21:19:17+09:00 Subject: [ruby-talk:21075] Re: Is this a problem with puts? Phil Tomson wrote: > I'm putting together a Ruby presentation for our local Linux user's group > and I ran into something that seems a bit odd... > > I can do: > puts /This is a regex/.type #-> prints: Regex (fine and good) > > but I can't do: > puts (42 .. 257).type #it prints: 42 .. 257 (instead of Range) > > but I can do: > whatType = (42 .. 257).type > puts whatType > > Why is this? > > I'm running: > ruby 1.6.2 (2000-12-25) [i686-linux] > > Phil > > I actually found your expected behavior, where it printed "Range". I assume this is because I'm using 1.7. I imagine it is printing the value and not the class for you because 'puts (42 .. 257).type' is being interpreted as '(puts (42 .. 257)).type'. It sees the range being passed as the sole argument to puts since it is surrounded by parentheses. 'puts (42 .. 257)' returns nil, which the method type is then applied to, resulting in a value of NilClass. So 'a = puts (42 .. 257).type' would result in a being NilClass. For me, 'puts (42 .. 257).type' prints Range while 'puts(42 .. 257).type' prints 42..257. (More) intelligence in 1.7? -- self.instance_of? RyanTarpine # => true