# Ruby in cmd

**URL:** <https://www.ruby-forum.com/t/ruby-in-cmd/106960>\
**Category:** Ruby\
**Created:** [June 15, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/ruby-in-cmd/106960 "2007-06-15T20:08:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@maung](https://www.ruby-forum.com/u/maung)\
**Post date:** [June 15, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/ruby-in-cmd/106960/1 "2007-06-15T20:08:54Z")

</div>

I am new to Ruby and am trying to run a piece of code from Programming  
Ruby in cmd. When i run in cmd \>ruby Song.rb, I don’t get any output.  
But I can get the result I expected when I run in irb. Can anyone help  
me on this?

class Song  
def initialize(name , artist, duartion)  
@name = name  
@artist = artist  
@duration = duartion  
end

```
def to_s
 "Song: #{system @name}--#{@artist} (#{@duration})"
end

def name
    @name
end

def artist
    @artist
end

def duration
    @duration
end

```

end

aSong = Song.new(“NAF”, “AS”, 300)  
aSong.to\_s  
aSong.artist  
aSong.name  
aSong.duration

---

<div class="post-metadata">

**Author:** ![maung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@maung](https://www.ruby-forum.com/u/maung)\
**Post date:** [June 15, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/ruby-in-cmd/106960/2 "2007-06-15T20:15:49Z")

</div>

maung schrieb:

> ```
> end
> @artist
> 
> ```
> 
> aSong.artist  
> aSong.name  
> aSong.duration

You need to put a puts/print in front of everything you want to output.  
So for example:  
puts aSong.to\_s

---

<div class="post-metadata">

**Author:** ![maung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@maung](https://www.ruby-forum.com/u/maung)\
**Post date:** [June 15, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/ruby-in-cmd/106960/3 "2007-06-15T20:17:49Z")

</div>

On 6/15/07, maung [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am new to Ruby and am trying to run a piece of code from Programming  
> Ruby in cmd. When i run in cmd \>ruby Song.rb, I don’t get any output.  
> But I can get the result I expected when I run in irb. Can anyone help  
> me on this?

As there is no print/puts/etc. statement, this non-output is expected  
from the file you wrote when run as a script.

irb is a read-eval-print loop. By default, it prints the output of the  
expressions and that’s why you see the output in this case.

---

<div class="post-metadata">

**Author:** ![maung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@maung](https://www.ruby-forum.com/u/maung)\
**Post date:** [June 15, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/ruby-in-cmd/106960/4 "2007-06-15T20:20:11Z")

</div>

Adriano F. wrote:

> On 6/15/07, maung [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I am new to Ruby and am trying to run a piece of code from Programming  
> > Ruby in cmd. When i run in cmd \>ruby Song.rb, I don’t get any output.  
> > But I can get the result I expected when I run in irb. Can anyone help  
> > me on this?
> 
> As there is no print/puts/etc. statement, this non-output is expected  
> from the file you wrote when run as a script.
> 
> irb is a read-eval-print loop. By default, it prints the output of the  
> expressions and that’s why you see the output in this case.

That’s explained it. Thanks a lot. It saved me a lot of time.

Maung

---

<div class="post-metadata">

**Author:** ![maung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@maung](https://www.ruby-forum.com/u/maung)\
**Post date:** [June 15, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/ruby-in-cmd/106960/5 "2007-06-15T20:22:50Z")

</div>

On Jun 15, 2:09 pm, maung [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
…

> aSong = Song.new(“NAF”, “AS”, 300)  
> aSong.to\_s  
> aSong.artist  
> aSong.name  
> aSong.duration

To see the output, you have to put it out 9^)

try:  
puts aSong.to\_s  
puts aSong.artist  
puts aSong.name  
puts aSong.duration
