Disable irb autocomplete - ruby

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

Related

File name completion in pry

I'm switching irb to pry. I just found that file name completion in pry didn't work.
I have a foo.rb in current directory, then I can complete file name like irb> load 'f[TAB], but this completion doesn't work in pry.
Is there configuration for this, or it is not possible to use file name completion in pry?
You can use "shell-mode" or "file-mode (alias for shell-mode)" in pry.

How to load ruby file in the pry editor?

I use pry with the standard editor vi.
Whenever i type 'edit' inside pry, vi shows up. That's good.
And with "load 'file'" i can run a ruby file in the pry session but when i type edit, the content of the file is not available in the vi editor of the pry session.
Is there a way to load a ruby file directly in the editor within pry?
As mudasobwa pointed out:
It's simple like 'edit myfile.rb'
and I end up with vi editing the file requested.

Ruby: How to load a file into interactive ruby console (IRB)?

I am using IRB (interactive ruby console) to learn how to program with Ruby. How do I load a file into the console if I write my programs in a text editor first?
If you only need to load one file into IRB you can invoke it with irb -r ./your_file.rb if it is in the same directory.
This automatically requires the file and allows you to work with it immediately.
Using ruby 1.9.3 on Ubuntu 14.04, I am able to load files from the current directory into irb with the following command line:
irb -I . -r foo.rb
where foo.rb is the file I want to load from my current directory. The -I option is necessary to add the current directory (.) to ruby's load path, as explained in the ruby man page. This makes it possible to require files from the current directory, which is what the -r option to irb accomplishes.
The key piece that wasn't obvious for me when I had this problem is the -I option. Once you do that, you can call require 'foo.rb' from within irb for any files in the current directory. And of course, you can specify any directory you want, not just . with the -I option. To include multiple directories on the load path, separate them with a colon (:), e.g.:
irb -I foo/:bar/:baz/
This command will add the directories foo, bar, and baz to ruby's load path.
The final alternative is to use the relative or absolute path to the file when using require or -r to load a file:
irb -r ./foo.rb
or from within irb:
> require './foo.rb'
Type in irb
And then
require './ruby_file.rb'
This is assuming that ruby_file.rb is in the same directory. Adjust accordingly.
Two ways:
to load source without running the program -- this gives access to all variables and functions:
source("filename.rb")
to run program and then drop into interactive mode -- this only gives access to functions, not variables:
require("filename.rb")
It depends on your ruby. Ruby 1.8 includes your current path, while ruby 1.9 does not. Evaluate $: to determine if your path is included or not. So in ruby 1.9 you must use the entire path, which is always a safe bet.
Then you can use require or load to include the file.
require does not require you to add the suffix of the file when trying to find it and will only include the file once. require should be used instead of load most of the time.
Check out Adding a directory to $LOAD_PATH (Ruby) if you are going to be using ruby 1.8
Type the ruby codes in the text editor
Save it with the extension .rb (for example: demo.rb).
In linux, open your terminal then change directory to the current location of that file (cd command is used to change directory).
After that,type irb and your filename(don't forget to include your extension(.rb)).
In that image,I loaded a simple ruby file which only prints "ruby".
Another way to load the path into irb is just type require then drag and drop the file into the terminal.🙂
-tested using Linux Mint.
For those, who want to load .rb file from the different directory. Just add a string representer of the directory to $: variable.
> $: << "/directory/to/the/required/rb/file"
> require "file"

don't load readline module in irb

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.

rbenv irb history is not saving

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

Resources