9

I have Installed Ruby On Rails of version 2.1.3p242 on my system. But I can't findout the ruby command line. I have searched but not found.

I have try to to check through

man ruby : Show some details

man rail : "See 'man 7 undocumented' for help when manual pages are not available."

May anybody help me to open the Ruby cmd line.

Nishant
  • 211
  • 2
  • 3
  • 9

2 Answers2

14

There are two ways of interactively using ruby on the command line (like running python or nodejs, for example):

Simply run ruby:

$ ruby
print "hello world\n"

Then press CtrlD. You will see:

hello world

The easier way is Interactive Ruby (irb):

$ irb
irb(main):001:0> print "hello\n"
hello
=> nil
irb(main):002:0> 
muru
  • 193,181
  • 53
  • 473
  • 722
  • I have use both the condition & I have got same result too. IT means ruby is fully configured in my system. – Nishant Dec 09 '14 at 11:27
  • @samzha I am no ruby expert, but I'd say that ruby seems to be working. – muru Dec 09 '14 at 11:29
  • actually I am working on a projects where SCSS file is used to handle the css. So for using SCSS I have to know how to use Ruby on rails. Without Ruby on rails I am unable to work on this. So for ruby command prompt which one is correct. – Nishant Dec 09 '14 at 11:30
  • @samzha That I cannot say. You should ask on [so]. – muru Dec 09 '14 at 11:31
  • But in stack overflow my question is offtopic. My question is that how can I open Ruby Command Line in ubuntu. How to use is the another thing. I want to know how to open. – Nishant Dec 09 '14 at 11:32
  • `irb` opens a Ruby command line. Use it. – muru Dec 09 '14 at 11:34
  • Are you sure because after `irb` irb(main):001:0> cd /opt/lampp/htdocs/myproject. It shows error : SyntaxError: (irb):1: unknown regexp options - lapp from /home/gwl/.rbenv/versions/2.1.3/bin/irb:11:in `
    '
    – Nishant Dec 09 '14 at 11:38
  • Why would you use `cd` in Ruby? – muru Dec 09 '14 at 11:41
  • to reach myproject folder. This procedure is used in windows for using `grunt` command. – Nishant Dec 09 '14 at 11:42
  • I think you need to start learning Ruby: http://stackoverflow.com/questions/3339883/to-change-directory-inside-a-ruby-script – muru Dec 09 '14 at 11:43
  • ok 'll try. I dont have much tym to read about ruby. Thanks @muru – Nishant Dec 09 '14 at 11:46
2

If you want a "Ruby command line" then you want irb

The command ruby is the non-command-line version. You can use that from the command line in several ways(*), but it is not a command line in itself.

As you didn't find irb, I guess you may not know about the command apropos The word means "pertinent information about" and typing

apropos ruby

will list a number of ruby-related things, including irb.

The argument for the command man usually must match the command or whatever exactly, so

man rail

would not find a manual page, even if there was one, man rails normally would, but I believe there is no rails man-page and you have to refer to the Ruby documentation for that.

(*) The usual Unix methods, e.e.:

  • As shown in the answer above.
  • echo 'print "hello world\n"' | ruby
  • ruby < my-ruby-prob.rb
  • The 'hereis' and 'shebang (#!) methods
Gordon
  • 593
  • 2
  • 5
  • 11
  • Thanks @Gordon. It mean that for Ruby command line I have configure the default terminal to Ruby cmd line. – Nishant Dec 09 '14 at 12:43
  • Please help me in one thing that like normal terminal if I want to goto my htdocs project folder I can go through `> cd /opt/lampp/htdocs/myproject`. Then in Ruby Command line i.e. `irb(main):001:0>` how can I reach my path. Please help @Gordon. – Nishant Dec 09 '14 at 12:46
  • If you mean you have set your terminal session so that it uses irb instead of bash, that would be very unusual, though may well work OK. Ruby is a programming language rather than a working environment, but if that works for you... I'm not an authority on Ruby, but I believe you want Dir.chdir("pathname"). – Gordon Dec 10 '14 at 10:50