irb icon indicating copy to clipboard operation
irb copied to clipboard

EVAL_HISTORY is busted

Open zenspider opened this issue 1 year ago • 7 comments

with IRB.conf[:EVAL_HISTORY] = true everything is busted:

9972 % irb
>> 1  + 2
/Users/ryan.davis/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb/ext/history.rb:127:in `>': comparison of Integer with true failed (ArgumentError)

      @contents.shift if @size != 0 && @contents.size > @size
                                                        ^^^^^
	from /Users/ryan.davis/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb/ext/history.rb:127:in `push'
	from /Users/ryan.davis/.rubies/ruby-3.2.2/lib/ruby/3.2.0/irb/ext/history.rb:26:in `set_last_value'

even irb_info

current .irbrc:

IRB.conf[:PROMPT_MODE]      = :SIMPLE
IRB.conf[:USE_AUTOCOMPLETE] = false
IRB.conf[:USE_COLORIZE]     = false

# maybe?

IRB.conf[:EVAL_HISTORY]     = true

zenspider avatar Nov 20 '23 21:11 zenspider

IRB.conf[:EVAL_HISTORY] should be number or nil.

Do you think IRB needs type validation for configs? Or EVAL_HISTORY=true should enable EVAL_HISTORY with some default size? (maybe about 10?)

These are some other confusing configs and invalid values that raise error.

IRB.conf[:IRB_NAME] = :ruby # should be string
IRB.conf[:IRB_RC] = '/path/to/.irbrc' # should be proc
IRB.conf[:BACK_TRACE_LIMIT] = ENV['IRB_BT_LIM'] # should be number
IRB.conf[:PROMPT] = '>> ' # should be hash

tompng avatar Nov 21 '23 10:11 tompng

Yeah both type validation and better documentation (discovery) are needed for those configs.

IRB.conf[:IRB_NAME] = :ruby # should be string

For this we should also support symbol, or even anything that responds to to_s?

Or EVAL_HISTORY=true should enable EVAL_HISTORY with some default size?

SAVE_HISTORY also doesn't support true (it has a default of 1000 though). So for consistency I'd say no, unless we want to change them both?

st0012 avatar Nov 22 '23 23:11 st0012

That's totally on me. I should have noticed that some default values were nil and some were not. I don't think we need full type checking, but some defensive programming would be nice... and doco. always doco

zenspider avatar Nov 30 '23 22:11 zenspider

@st0012 want me to file a separate bug against doco and type checking?

zenspider avatar Mar 18 '24 05:03 zenspider

@zenspider Sorry for the delay. I've now cleared other priorities and will start looking at this. For the start I'll target the configs listed here, so feel free to add new ones.

st0012 avatar May 06 '24 14:05 st0012

Actually, I think I'll close this with https://github.com/ruby/irb/pull/953. If you find other configs can use the same improvement, please open new ones 😄

st0012 avatar May 06 '24 17:05 st0012

#953 feels like the right thing to do. Thanks!

zenspider avatar May 06 '24 17:05 zenspider