Hi
I am reading a book about ruby, it learn me that I write my program in
SciTE and then use F5 in keyboard to run my program.
Now , today I write this very very simple program :
a = gets.chomp!
when I write this code in Interactive Ruby enviroment , this code runs
as I want but when I write this code in SciTE and use F5 after some
seconds a black window opens and I can’t write anything and I can’t use
“gets” instruction in my program.
please help me.
thanks
Back when I used SciTE, it didn’t have anyway for you to pass data to
standard input. If it’s still like this, then you will have to go to the
terminal and run your program with the ruby interpreter $ ruby yourfile.rb
i use SciTe regularly, and like it a lot, but unfortunately #gets will
not work with it… you’ll have to run the program from the terminal as
mentioned above.
SciTE is great for its highlighting, and the fact that you can run
(most) scripts by pressing F5 - unfortunately, the “gets” method won’t
work with SciTe… you’ll have to run the program from a terminal.
under ubuntu / linux it should be in Main Menu -> Accessories ->
Terminal, under windows i think it’s Start -> Run, but i’m not sure
(google it)
let’s say that your program is named “my_program.rb” - in the terminal
type:
ruby my_program.rb
this should run the program, and let you use the “gets” method as you
expect.
Hi
I have a problem with ruby documentation , I mean that I don’t
understand ruby documentation for example in the image that is attached
to this file I don’t understand meaning of highlighted sections.
Please someone explain completely .
thanks
i use SciTe regularly, and like it a lot, but unfortunately #gets will
not work with it… you’ll have to run the program from the terminal as
mentioned above.
j
It is hard to find, but possible to enter data from stdin
with SciTE.
Just press F8 (so the output-pane is visible) and enter the data there.
Additionally, the OP should use chomp instead of chomp! as the latter
may return nil.
Bartosz Dziewoński , I am very thankful from you. but I have another
question I don’t understand exactly what is the [,opt] and how can I use
that ?
thanks
The square brackets are there simply to indicate this is an optional
argument.
You can sometimes even come across methods that have nested brackets -
e.g. something( arg1 [, arg2 [, arg3 ]] ) - this simply means that all
arguments except the first are optional. This is a quite widely used
convention, also present in, for example, PHP documentation.
the dark-grey header shows variants of this method’s signature, that
is, how you can use it.
** first comes the class name and the method name
** then, in parentheses, description of arguments. “fd” argument is
mandatory, “mode_string” is optional with default value being “r” (why
“r” is explained below), “opt” is also optional with no default value.
** later, only in the second variant, comes the information how you
can call this function with a block.
** finally, after the arrow, what is the value returned by this
variant. First variant returns an IO object, second returns the value
of the block (this is, once again, explained in the text below).
– Matma R.