Questions tagged [irb]
Interactive Ruby (IRB) is a shell for programming in Ruby. The program can be launched from a command prompt and allows the execution of Ruby commands line by line.
772
questions
0
votes
2
answers
41
views
Why Visual studio don't give me an output?
i'm newbie in Ruby. Today i was coding some home exercise and founding this behavior of my code: if i try to execute the same code in irb and VSC in second case i don't get a single string of output.
...
0
votes
1
answer
25
views
Prevent Rails console from removing consecutive linebreaks
I'd like to prevent the Rails console from removing consecutive linebreaks:
CoolApp (PRODUCTION) > a = '
CoolApp (PRODUCTION) " hi
CoolApp (PRODUCTION) "
CoolApp (PRODUCTION) "
...
0
votes
1
answer
41
views
IRB Keyboard Shortcuts are disabled? Can these be re-enabled? What did I break?
Expected behavior:
Keyboard shortcuts using readline shortcuts like this answer.
What actually happens: Ctrl+l is pressed to clear the screen
irb
2023-08-08 20:31:17 -0600
Loaded Profile methods
irb....
1
vote
2
answers
64
views
How can remove multiline output with Rails console (Rails 6.1.7.2/Ruby 3.1.2)?
After upgrading to Rails 6.1.7.2 and Ruby 3.1.2, the way ActiveRecords are displayed in the output of the rails console is really annoying me. Basically, each record's attributes and values are ...
0
votes
0
answers
75
views
Ruby multistage build are failing
While deploying/testing the Ruby application locally I'm getting this error:
root@bbd7925ec418:/# docker-compose up --build
Error response from daemon: failed to create shim task:
OCI runtime create ...
5
votes
2
answers
294
views
Rails 7 IRB console inserts escape key instead of execute delete command
I am using Mac OS and since latest rails version the delete key does not work anymore.
❯ rails -v
Rails 7.0.4
❯ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
When I hit ...
0
votes
1
answer
39
views
What is the traceback/local jumpback error in irb repl when writing multiline code?
I am a newbie, forgive if this is an obvious question but does anyone know why my irb repl isn't able to do multilines? I have tried lots of different if statements (copied from course notes that I am ...
0
votes
1
answer
305
views
Rails console overriding `~/.irbrc`
I have the following in my ~/.irbrc file:
require 'irb'
require 'rubygems'
require 'awesome_print'
AwesomePrint.irb!
IRB.conf[:USE_AUTOCOMPLETE] = false
IRB.conf[:ECHO_ON_ASSIGNMENT] = true
IRB.conf[...
-3
votes
1
answer
518
views
Ruby on Rails undefined local variable or method in console [closed]
What is problem? I don't understand.
2
votes
0
answers
99
views
adding search function to my rails API (with pg_search), model comming from external DB, getting Object doesnt support #inspect
i know there are several questions like this one, but this is a bit different since my model is not stored in rails database, it is coming from an external db.
I implemented pg_search in the model, ...
6
votes
4
answers
488
views
Ruby 3 IRB home end and ctrl-u not working
I've recently started using Ruby 3 more and it seems the home key (to take me to the beginning of the line) the end key (end of the line) and ctrl-u (clear the line) aren't working.
I'm running Arch ...
0
votes
1
answer
266
views
No history for rails console
irb works fine, rails console doesnt!
~/.irbrc
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
> irb
irb(main):...
-1
votes
1
answer
128
views
How to copy object from one shell to another shell?
You have two open IRB shells in separate terminal windows. The first shell has the following code already entered:
class Apple
attr_reader :variety, :origin, :history
def initialize(**args)
@...
0
votes
1
answer
110
views
Copy paste from irb excluding prompt at start of line?
When copy/pasting from irb to an .rb file the start of each line should be removed.
A short example, say you copy this from irb:
irb(main):049:1* def thing(x, y)
irb(main):050:1* out = x * y
irb(...
0
votes
0
answers
127
views
Ruby gem - How do I test my own ruby gem via IRB?
Okay so I am completely new to using IRB so I have no idea what I am doing wrong.
Here is my gem that I built
# frozen_string_literal: true
require_relative "badwordgem/version"
require '...
1
vote
0
answers
144
views
Rails console (in docker-compose) hangs when I try to paste a string with an extended character such as "Vötest"
On my Mac:
Copy the string n = "Vötest" to my clipboard from my code editor (Sublimetext 3.2.2)
Launch Rails console
rails c
irb(main):001:0>
Attempt to paste the string to ...
2
votes
1
answer
53
views
How to make irb output the same on Ubuntu and Windows?
I'm have irb 1.4.1 (2021-12-25) on Windows 10 and Ubuntu 16.04. On Windows, When I type in irb 1+2, on Windows I get # => 3, but on Ubuntu I get => 3.
For me this is not a trivial matter, ...
1
vote
2
answers
159
views
Ruby 3.1.0 encoding(?) problem in irb (RubyInstaller Windows 10)
Since the update to 3.1.0 via RubyInstaller under Win 10 there is a problem with alt gr in irb. When I try to enter { (German keyboard alt gr + {) I get ^[{. Any idea what's going wrong? BTW 3.0.2 was ...
0
votes
0
answers
52
views
Remove ruby 3.1 autocomplete feature for heroku console [duplicate]
The autocomplete feature from Ruby 3.1 is really nice on local environment but makes the one-off Heroku dyno really slow. How could I remove the autocompletion with an .irbrc file?
I tried something ...
8
votes
3
answers
2k
views
Disabling irb autocomplete on Heroku
A follow up to Disable irb autocomplete
I would like to disable IRB on Heroku, e.g. having an .irbrc with:
IRB.conf[:USE_AUTOCOMPLETE] = false
In the home directory of my heroku dyno/server
How can I ...
74
votes
3
answers
11k
views
Disable irb autocomplete
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 ...
1
vote
2
answers
590
views
Ruby console - Multiline command with exit
I have a simple ruby script I would like to run in the rails console, using bundle exec rails c
ids = [1, 2]
if ids.length() > 5
puts "More than 5 ids, quitting"
exit
end
ids....
1
vote
1
answer
375
views
Possible to configure rails to load per project .irbrc file?
Can rails load .irbrc from the rails project root such as ~/rails-projct/.irbrc. Rather then ~/.irbrc. Since it would be nice to add configuration that's specific to a project.
1
vote
1
answer
195
views
How can I paste multiple line command with Docker interactive mode but not evaluating?
For example I am opening an interactive command line window.
docker exec -it container rails c
When I paste a multiple-line command, it evaluate every line instead of pasting a block. How can I ...
2
votes
1
answer
481
views
how can options be passed to rails console in heroku
While trying to pass options to rails console in Heroku the following error is shown:
> heroku run rails console -- --nomultiline
Running rails console "-- --nomultiline" on ⬢ the-app... ...
0
votes
2
answers
70
views
How do I access functions of an instance variable of a class, within another class?
Take this for example:
class Inner
attr_accessor :id, :number
def initialize(id, number)
@id = id
@number = number
end
def id()
...
0
votes
0
answers
201
views
Rails console doesn't work after update RoR
After update rails to 6.1.4 version and ruby to 3.0.0 and update my Ruby on Rails APP I cant start the rails console either IRB and it doesn't show any error.
Tests performed
I have installed the IRB ...
0
votes
2
answers
432
views
Ruby irb utf-8 encoding problem on windows 10 terminal input
I want to use ruby with terminal input in my windows. Why ruby community can not solve this UTF-8 issue on windows? Is it hard? I am wondering how python, java or other langs did this? I can work ...
1
vote
1
answer
687
views
Why 'irb' shell exits instantaneously in docker command
This is my Dockerfile.
FROM ruby:2.4.0-alpine
RUN mkdir /app
WORKDIR /app
COPY Gemfile ./Gemfile
COPY Gemfile.lock ./Gemfile.lock
RUN bundle install -j 20
COPY . .
This is my docker-compose file:
...
2
votes
1
answer
2k
views
Ruby NoMethodError (undefined method ''...' for '....:Class'
require_relative 'json_lookup'
require_relative 'csv_lookup'
require_relative 'error'
BASE_RATE = 'EUR'
class CurrencyExchange
def initialize(file:, date:, from:, to:)
@file = file
@date =...
12
votes
4
answers
3k
views
how can I change the default syntax coloring in ruby 3.0's IRB
I'm very happy to be using the most recent ruby 3.0; as well as having access to the updated command-line interpreter which does syntax highlighting and coloring.
However, the colors are a bit hard to ...
2
votes
0
answers
28
views
How can I consistently prefix IRB return values with a custom comment string in Ruby >= 3.0.0?
I have the following in my ~/.irbrc file:
IRB.conf[:PROMPT][:DEFAULT][:RETURN].prepend ?#
In earlier Ruby versions, this would ensure that each return value was prefixed with a comment symbol rather ...
1
vote
0
answers
214
views
Why doesn't IRB display output when executing in VS Code Terminal?
Newbie here.. I'm trying out VS Code and am running into an issue. I've connected VS Code to WSL through remote connection and everything is running great expect for IRB.. When I open IRB in the ...
0
votes
3
answers
327
views
Automatically load Dotenv on my ruby console
I'd like to automatically run Dotenv.load('.env.development') whenever I launch up a ruby console, it could either be from bundle console or alternatively irb. I'm using Sinatra, not Rails, and I'm ...
0
votes
1
answer
165
views
Ruby: how to access group info from /var/db/group.db
RHEL/CentOS 8.x, Ruby 2.5.5, irb 0.9.6
We have a specialized set up that keeps user and group information in /usr/local/etc/[user|group] and a custom Makefile to add that information to /var/db/[group|...
1
vote
1
answer
84
views
In irb while defining a method named 'method', wrong number of argument apperaed
after define a method named 'method' in irb/gry
def method
puts 1
end
Traceback (most recent call last):
33: from F:/Ruby27-x64/bin/irb.cmd:31:in `<main>'
32: from F:/...
6
votes
2
answers
801
views
How can I add a new line in Ruby 2.7+ IRB multiline edit mode?
Ruby 2.7 introduced an update to IRB that allows multiline editing. How can I add a new line into a multiline method to inject code between two previous statements?
E.g.
2.7.1 :019 > while session =...
0
votes
1
answer
77
views
Using .reverse in irb
In IRB,
.sort is working well.
(1..10).to_a.sample(5).sort => [1, 3, 6, 8, 9]
However, .reverse is not working
(1..10).to_a.sample(5).reverse => [4, 3, 10, 2, 1]
How can I get result of that is ...
0
votes
1
answer
196
views
Ruby on Rails testing connection to DB through irb , NameError Uninitialized Constant Article
I’m running into an issue where I want to test out the connection to the db. I’m trying to access my Articles table. I have a file in models “article.rb” and inside it has:
class Article < ...
-1
votes
1
answer
426
views
For loop not working with string.length in Ruby irb
In irb, bash shell, on a mac. As you can see, a is a defined array. Putting a.length in parens makes no difference. The output should be the array, but no output appears.
>> a
=> ["ant&...
1
vote
0
answers
34
views
Ruby object's console view beautifier - is there something like that?
In Ruby console we can show an object in a form like that:
#<ActiveSupport::Cache::MemcachedStore:0x00005649aedceb20 @swallow_exceptions=true, @options={:namespace
=>"dfw_cache", :...
0
votes
1
answer
56
views
What's the difference between TOPLEVEL_BINDING and binding?
I opened irb and checked the value of binding and TOPLEVEL_binding:
2.7.0 :021 > TOPLEVEL_BINDING
=> #<Binding:0x00007fbd7d85bb18>
2.7.0 :022 > binding
=> #<Binding:...
-1
votes
1
answer
226
views
Can I instantiate a class from a method within another class? (Ruby)
I've redone the question and included the full code for both files. In the touch_in method I am trying to instantiate a Journey class in the variable called 'journey'.
require_relative 'journey'
...
3
votes
2
answers
1k
views
Why is the RubyMine console failing to start?
I'm running the latest RubyMine, 2020.1.1 (Build #RM-201.7223.94), Ruby 2.7 and Rails 6.0.2.2. When I try to start a Rails console, I get this error:
C:\Users\pupeno\scoop\apps\ruby\current\bin\ruby....
0
votes
0
answers
660
views
Visual Studio code. Terminal. Arrows don't work in Irb and Rails Console
I can observe really weird behavior of the integrated terminal in VSCode.
When I work with irb or rails console (for my Ruby on Rails project), the arrow keys don't work.
So I can't use my command ...
1
vote
1
answer
100
views
Simulating selecting a file for Active Storage in irb
Creating a new item for Active Storage.
<!-- app/views/docs/_form.html.erb -->
<%= f.label :image, "Select document or image that support this information." %>
<%= f.file_field :...
1
vote
1
answer
626
views
Is it possible to place the .irbrc file in the project folder?
I would like to place the .irbrc file in my project folder to configure the irb console just for that specific project. I am aware that i can configure .irbrc placing it in the home folder but i would ...
0
votes
1
answer
446
views
Memory leak in ruby
I have such code in irb:
2.6.3 :001 > a = []; 100000000000.times do a.push([1]) end
^CTraceback (most recent call last):
3: from (irb):1
2: from (irb):1:in `times'
1: from (...
0
votes
0
answers
145
views
Rails Console is not querying the table in Rails 6
Altruists,
I am new in Rails, I have a devise user model named Account. I have signed up with my email, and I want to query my Account table from rails console, like I did in Rails 5 without any ...
0
votes
1
answer
154
views
Debug Ohai plugins in irb shell
I've installed a chef-workstation on my computer.
ohai --version #returns: 15.7.4
I also installed the Ohai cookbook from the supermarket. If I integrate this into my test cookbook, the self-...