What's wrong with this?

Hey everyone, I'm very new to Ruby and I'm starting to do a bit more
hands-on practice... So I decided to make an attempt at making a small
bit of code, but when I run it, nothing happens... Can someone please
explain why?...

Here is what I have so far:

class RoboEngine

  def initialize
   puts "Initializing..."
   Init.action1
  end

end

class Initialization

  def action1
    puts "Initialized!"
    sleep(0.3)
    puts "Loading Thought Process..."
  end
end

Init = Initialization.new

So why is it that when I run this, nothing happens? Nothing is
printed...

···

--
Posted via http://www.ruby-forum.com/.

Well the only class being initialise in the Initialization class, you
could delete the whole RoboEngine class from your code because nothing
is using it

Put this after the last line

RoboEngine.new

and try again

You create an object of class Initialization and assign it to the constant
Init. The only methods which are called is Initialization#initialize, called
from Initialize.new. Since you haven't defined it, Object#initialize is used
instead and it does nothing.

I guess what you want is to also create an instance of RoboEngine, after
creating the Initialization object:

Init = Initialization.new
robo = RoboEngine.new

I hope this helps

Stefano

···

Il giorno Sun, 22 Jan 2012 04:56:33 +0900 Paet Worlds II <paetilium@live.com> ha scritto:

Hey everyone, I'm very new to Ruby and I'm starting to do a bit more
hands-on practice... So I decided to make an attempt at making a small
bit of code, but when I run it, nothing happens... Can someone please
explain why?...

Here is what I have so far:

class RoboEngine

  def initialize
   puts "Initializing..."
   Init.action1
  end

end

class Initialization

  def action1
    puts "Initialized!"
    sleep(0.3)
    puts "Loading Thought Process..."
  end
end

Init = Initialization.new

So why is it that when I run this, nothing happens? Nothing is
printed...

Stefano Crocco wrote in post #1041949:

···

Il giorno Sun, 22 Jan 2012 04:56:33 +0900 > Paet Worlds II <paetilium@live.com> ha scritto:

    puts "Initialized!"
So why is it that when I run this, nothing happens? Nothing is
printed...

You create an object of class Initialization and assign it to the
constant
Init. The only methods which are called is Initialization#initialize,
called
from Initialize.new. Since you haven't defined it, Object#initialize is
used
instead and it does nothing.

I guess what you want is to also create an instance of RoboEngine, after
creating the Initialization object:

Init = Initialization.new
robo = RoboEngine.new

I hope this helps

Stefano

Thank you both so much!! But could you please give me a very basic
explanation as to why it did not work before? o,o

-Thanks a ton!

--
Posted via http://www.ruby-forum.com/\.

Because the only methods which print something on the screen are
RoboEngine#initialize and Initialization#action1, and you didn't call any of
them.

Stefano

···

Il giorno Sun, 22 Jan 2012 05:37:10 +0900 Paet Worlds II <paetilium@live.com> ha scritto:

Stefano Crocco wrote in post #1041949:
> Il giorno Sun, 22 Jan 2012 04:56:33 +0900 > > Paet Worlds II <paetilium@live.com> ha scritto:
>
>>
>> puts "Initialized!"
>> So why is it that when I run this, nothing happens? Nothing is
>> printed...
>>
>
> You create an object of class Initialization and assign it to the
> constant
> Init. The only methods which are called is Initialization#initialize,
> called
> from Initialize.new. Since you haven't defined it, Object#initialize is
> used
> instead and it does nothing.
>
> I guess what you want is to also create an instance of RoboEngine, after
> creating the Initialization object:
>
> Init = Initialization.new
> robo = RoboEngine.new
>
> I hope this helps
>
> Stefano

Thank you both so much!! But could you please give me a very basic
explanation as to why it did not work before? o,o

-Thanks a ton!