How to use Cyirllic alphabets in ruby rails in irb in ruby 2.1 version - puts

i am unable to enter cyrillic alphabets in ruby irb. I have installed cyrillizer,translit and try to paste cyrillic alphabets in irb but it doesnt allow me to paste into command prompt

Related

I can't run my Ruby program and I see errors in the terminal. I can't find the program

Good afternoon! I have a problem with Ruby. I downloaded this program from the official site https://www.ruby-lang.org/en/downloads/ on Fedora without any problems (using the command via the terminal). However, I cannot use the 'irb' command in the terminal to run Ruby on Linux as described here https://www.ruby-lang.org/en/documentation/quickstart/. Therefore, I cannot learn the Ruby programming language.Command 'irb' not found
I tried my best to run Ruby in other ways. One of them, as is customary in Fedora, is to write the name of the program in the terminal. But it opens a folder in which, I assume, Ruby is located (I can't find the folder itself either in Files or via the 'cd' command in the terminal). I kind of can open this folder in the terminal, but I can't find it in Files.
Oh, by the way, the 'irb' command doesn't work there. Only some real command for a program like this one will work: irb(main):001:0> "Hello World" (from https://www.ruby-lang.org/en/documentation/quickstart/). The program is and is not at the same time
Move on. I made a text document, wrote irb(main):001:0> "Hello World" in it (as written in "Ruby in Twenty Minutes"), and saved the file as hello.rb . Opened the hello.rb file path through the terminal and wrote 'ruby hello.rb' (without quotes, of course). Result: syntax error. hello.rb file Tried to open hello.rb via ruby in terminal
Oh yeah, I almost forgot: when I tried to open hello.rb in Files through another application, there was no Ruby script in the list (ruby or irb or at least something through which one could open a .rb file). No program for .rb format
I hope I have explained the problem in sufficient detail and clearly. And I hope for your help and understanding! In any case, good mood to you!
On Fedora & CentOS, the Ruby installation is split into many smaller packages. If you want to run irb, you'll also have to install the ruby-irb package using dnf install ruby-irb.

Can Ruby Koans be run on a mac?

I have ruby koans installed on a mac but when I enter
$ ruby path_to_enlightenment.rb
to start it, I get:
bash: $: command not found
Try entering ruby path_to_enlightenment.rb instead. With no $.

"require" command not found when require 'nokogiri'

Homebrew, ruby 2.0.0p648, nokogiri 1.6.7.2 are installed. When require 'nokogiri' there appears an error:
-bash: require: command not found
What's wrong?
Try running the script from the console/terminal shell like this:
ruby script_name.rb
You can also try adding this shebang line to the top of your .rb file:
#!/usr/bin/env ruby
This will auto-identify the script as Ruby when you try to run it directly in some shells. Also see:
Why is it better to use “#!/usr/bin/env NAME” instead of “#!/path/to/NAME” as my shebang?
what is the use of “#!/usr/local/bin/ruby -w” at the start of a ruby program
You're running your command in bash -- this is a Ruby command.
You can't run a Ruby command directly in bash. If you want to use Ruby at command line, open the Ruby shell irb.
$ irb
and then you'll see the prompt
2.3.0 :001 >
The first number indicates the Ruby version you are using. In my case it is Ruby 2.3.0. The second number is the command number.
Then you may type
require 'nokogiri'
and it surely work, if you have this gem installed.

Why won't macvim always use ruby 1.9.3?

I have installed yadr dotfiles, a set of vim, ruby, etc plugins.
I have the following line of Ruby code in a file foo.rb:
foo: bar
Note I used the ruby 1.9.3 syntax for symbol assignment/definition.
When I start macvim from command line using mvim foo.rb and save that file, everything works fine.
However, when I open macvim using open -a macvim and navigate to and open foo.rb, when I try to save the file I get a ruby-vim syntax error on foo: bar. When I change it to :foo => bar I don't get syntax errors.
Using open -a macvim to open macvim, and then entering :!ruby -v prints ruby 1.8.7
Using mvim . to open macvim, and then entering :!ruby -v prints ruby 1.9.3
Depending on how I open macvim, I get a different version of Ruby. How do I ensure that macvim always uses ruby 1.9.3 to evaluate my ruby code?
Thanks
It took me awhile to find a fix, but the issue is caused by MacVim not loading zsh the same way Terminal loads zsh.
The fix is easy enough and can be placed into your zshrc. See a commit from my dotfiles:
https://github.com/simeonwillbanks/dotfiles/commit/e0e19cfeff13f8bc99d8164217ddd84c6d7f9529
The commit references a full explanation which can be found here:
http://vim.1045645.n5.nabble.com/MacVim-and-PATH-tt3388705.html#a3392363
Hope this helps!

Ruby regex works with ruby command but not shebang

I have the following 2 regular expressions in a ruby file. They run fine when i use the ruby command but if i try to run via ./apachereport.rb it generates an error.
regex:
urls = parse(#file, /(?<=GET )\S+/)
codes = parse(#file, /(?<=HTTP\/[0-9]\.[0-9]" )\S+/)
error:
./apachereport.rb:34: undefined (?...) sequence: /(?<=GET )\S+/
./apachereport.rb:47: undefined (?...) sequence: /(?<=HTTP\/[0-9]\.[0-9]" )\S+/
The shebang I'm using is as follows, which seems to work fine with other ruby files:
#!/usr/bin/ruby
The most likely explanation for this is that you have multiple versions of ruby installed. The version installed in /usr/bin (which is the one you're using in your shebang line) is 1.8.X, which did not support ?<= (look-behind) in regexen. The one you execute when you type ruby apachereport is probably ruby 1.9, which does support ?<=.
To verify that this is the case type in which ruby and notice that it prints something other than /usr/bin/ruby and/or compare the results of /usr/bin/ruby --version to ruby --version.

Resources