How to create console application

Hi All,

I want to create a console application using ruby. Can you please
provide me the details/idea?

Lots of thanks,
Priya

On 27 January 2011 04:48, Priya D. [email protected] wrote:

Hi All,

I want to create a console application using ruby. Can you please
provide me the details/idea?

That is nothing to do with RoR of course, but just write a file.rb run
it by
ruby file.rb
You can use puts etc to access the console.

Colin

I want to create a new console using ruby code. From the new console,
i’ll execute my commands.

On 27 January 2011 09:20, Priya D. [email protected] wrote:

I want to create a new console using ruby code. From the new console,
i’ll execute my commands.

What do you mean by create a new console? Please describe in more
detail what you are trying to do.

Colin

I’m creating a new object for a class using irb. At that time, if the
object is created successfully, a new console should be open. The newly
opened console should act as the created object.

so that i can execute all the instance methods through the newly opened
console, without prefixing object to the methods.

am i clear?

On 27 January 2011 09:31, Priya D. [email protected] wrote:

I’m creating a new object for a class using irb. At that time, if the
object is created successfully, a new console should be open. The newly
opened console should act as the created object.

so that i can execute all the instance methods through the newly opened
console, without prefixing object to the methods.

You can use the ruby method ‘system’ to run system commands to open a
command shell if that is what you mean.

Colin

No Colin, i don’t want to execute system commands.

For eg,

  1. I’m requiring a gem in console.(require “somegem”)
  2. I’ll create object of the gem. (@obj = Module::Class.new)
  3. Using the created object, i’ll access the methods in the gem.
    (@obj.get_details())

In the above mentioned steps, while i’m creating a object, a new console
should open, which represents the object.

I just give the instance method names in the opened console.i.e,
get_details() instead of @obj.get_details().

Is this making sense?

On 27 January 2011 09:47, Priya D. [email protected] wrote:

should open, which represents the object.

I just give the instance method names in the opened console.i.e,
get_details() instead of @obj.get_details().

Is this making sense?

Which OS are you running (Ubuntu, XP etc)? How do you open the first
console?

Colin

On 27 January 2011 11:04, Priya D. [email protected] wrote:

Am using Ubuntu 10.04. Just using irb.

Please don’t top post, it makes it difficult to follow the thread,
insert your reply into the previous post, thanks.

So to open a console you open a terminal window and then run irb. If
you want to open another console then AFAIK you will need to run a
system command to open another terminal and run irb. Something like
system( ‘gnome-terminal -e irb’)
Unless someone knows another way.

Colin

Am using Ubuntu 10.04. Just using irb.

Colin L. wrote in post #977860:

On 27 January 2011 11:04, Priya D. [email protected] wrote:

Am using Ubuntu 10.04. Just using irb.

Please don’t top post, it makes it difficult to follow the thread,
insert your reply into the previous post, thanks.

So to open a console you open a terminal window and then run irb. If
you want to open another console then AFAIK you will need to run a
system command to open another terminal and run irb. Something like
system( ‘gnome-terminal -e irb’)
Unless someone knows another way.

Colin

Sorry Colin, i think you didn’t get my requirement. Thank you very much
for your valuable effort.

Anyway, i’m working on this. If i get the solution, i’ll reply. Thanks.

I think you can use Irb to jump into another object :
http://www.ruby-forum.com/topic/182335
irb Mix Tape — err.the_blog (3rd paragraph)

Here is something that I created for myself to have capybara console:
It creates and object, extends it with the capybara api and jumps into
it.

I couldn’t find an easier way to jump into an object with irb at the
beginning of the session.

I hope this will help.

Robert Pankowecki

On Thu, Jan 27, 2011 at 2:31 AM, Priya D. [email protected] wrote:

I’m creating a new object for a class using irb. At that time, if the
object is created successfully, a new console should be open. The newly
opened console should act as the created object.

so that i can execute all the instance methods through the newly opened
console, without prefixing object to the methods.

am i clear?

The concept of nested irb shells is already supported by irb. You
merely
have to use the method “irb ” while in irb to insert yourself
into
the instance’s namespace.

irb(main):001:0> class Test
irb(main):002:1> def test_method
irb(main):003:2> “test method called correctly”
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> irb Test.new
irb#1(#Test:0x1c67478):001:0> test_method
=> “test method called correctly”
irb#1(#Test:0x1c67478):002:0> quit
=> #<IRB::Irb: @scanner=#RubyLex:0x1bac510,
@context=#IRB::Context:0x1bacbc8, @signal_status=:IN_EVAL>
irb(main):007:0> quit
bash%

Josh