nonsequitur / inf-ruby

218 stars 69 forks source link

Unable to `ruby-send-region` commonly formatted multiline code. #139

Closed vikdotdev closed 4 years ago

vikdotdev commented 4 years ago

Issue occurs with ruby-send-region command when I'm trying to evaluate code with very common format.

For example:

project_ids = ExceedinglyLongModelName
                .where(employee_id: user.employee_id)
                .pluck(:project_id)

returns the following result:

# only first line is evaluated which leads to the following output
=> ExceedinglyLongModelName(id: integer, employee_id: integer, project_id: string)

Expected result:

# entire region is evaluated
=> [ 1, 2, 3 ]  

With little experimentation I noticed that when line ends with a dot, it evaluates properly:

project_ids = ExceedinglyLongModelName.
                where(employee_id: some_user.employee_id).
                pluck(:project_id)

Solution

As I was formulating my issue I found a solution in pry issues and decided to still post it here, as it might be useful to someone else.

Pry.commands.delete /\.(.*)/ can be put into ~/.pryrc and it should work.

vikdotdev commented 4 years ago

This can be closed now.

dgutov commented 4 years ago

Thanks for the workaround. This only works inside begin...end or def...end though, right?

dgutov commented 4 years ago

Never mind. Should work in any file-based buffer with ruby-send-region. Just not inside the REPL itself.