The readline extension on my OSX seems buggy.
$irb -f --noreadline
irb(main):001:0> "中文"
=> "中文"
$irb -f --readline
irb(main):001:0> \U+FFE4\U+FFB8\U+FFAD\U+FFE6
So I want to set --noreadline as default option for irb. how to do it?
p.s. I'm using RVM and Ruby 1.9.3p194.
Add the following to your ~/.irbrc file (create it if it doesn't exist):
IRB.conf[:USE_READLINE] = false
Alternatively, you can add this to /etc/irbrc if you want it to apply across user accounts, or foo/.irbrc if you want it to apply on a directory/project basis.
Here's a list of other useful config options.
Related
The latest version of irb introduced an autocomplete that is quite buggy and I don't generally like to be distracted by an autocomplete, any idea how I can disable it?
Related question: How to disable Pry autocomplete?
Try putting this in your ~/.irbrc
IRB.conf[:USE_AUTOCOMPLETE] = false
We can pass the --noautocomplete command line option when invoking IRB.
irb --noautocomplete
Alternatively we can set a configuration option in ~/.irbrc or one of the other locations specified in the documentation
IRB.conf[:USE_AUTOCOMPLETE] = false
Starting a Rails console will respect this configuration but for a one-off we can provide the command line option.
Be sure to pass any Rails options before the --
rails console --sandbox -- --noautocomplete
Linux: locate .irbrc file. If there is no .irbrc file - create one in your home folder - type the following command into terminal:
echo "IRB.conf[:CONTEXT_MODE] = 0" >> ~/.irbrc
Windows: locate .irbrc folder
C:\Users\Ben\ .irbrc
Then to disable autocomplete add this line to .irbrc file:
IRB.conf[:USE_AUTOCOMPLETE] = false
I install ruby via rbenv-installer.
When I use irb console, I can use history by pressing up and down on keyboard. And when I exited from console and start it again, I can't use prewious history. When I press up-arrow-button, nothing was happened.
When I used rvm this option was working. How can I switch on it in rbenv?
I found this way for solving my problem. In file ~/.irbrc write:
require 'irb/ext/save-history'
#History configuration
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
Found in this question: irb history not working
Create ~/.irbrc if it does not exist, and add the following line to it:
IRB.conf[:SAVE_HISTORY] = 1000
Can any body guide me to ruby gem that changes font-size and color of irb terminal output dynamically. If not gem is there any other method to lighten up terminal and/or irb?
Also you can try to use pry. It's alternative to irb shell. It has colorized results out of the box and much more.
There is RailsCast about it.
I asked DuckDuckGo and it told me that you should look at: fancy_irb
$ sudo gem install fancy_irb
$ irb
> require 'fancy_irb'
=> true
> FancyIrb.start
=> "Enjoy your FancyIrb :)"
I'm using ruby v1.9.1 in combination with vim and I execute my scripts with:
:!ruby "%"
my scripts are running fine if I add:
$:.unshift File.dirname(__FILE__)
to add the path of this file to the LOAD_PATH of ruby. If I omit this line my require statements to local scripts aren't working anymore.
Is there a way to pass the path of the file to rubys LOAD_PATH? Something like (completly fictional):
:!ruby "%" --add-to-load-path
I did some research before and stubled upon require_relative, but this has the same effect as require and is not working.
You can use the -I option of the ruby executable and write something like the following:
:!ruby -I%:p:h. %
See ruby --help for further information and file modifiers.
Edited: see comments.
When running ruby scripts as such
ruby some-script.rb
How would I include a file (e.g. configuration file) in it dynamically?
As you have found, the -r option is your friend. It also works with IRB:
irb -ropen-uri
Will do the same as require 'open-uri'
FWIW, the most common thing I need to include via the command line is rubygems. And since newer versions of ruby come with gems built in I don't want to edit the file, but include it for testing. Luckily the folks who created gems added a little alias sugar.
You can do the following:
ruby -rubygems myscript.rb
Instead of the ugly:
ruby -rrubygems myscript.rb
OK, so it is one character, but thought it was extra polish to make me happier.
Actually, I found it. It's the -r command line entry.
-r <library_name>
This causes Ruby to load the library using require.
It is useful when used in conjunction with -n or -p.
You can use:
require 'some_ruby_file'
in some-script.rb. It will load some_ruby_file.rb.
Before you call require "somefile.rb" you must navigate to the folder that the file is located or you must provide the full path. In example: require "~/Documents/Somefolder/somefile.rb"