Skip to content

Commit 314460a

Browse files
committed
Don't def encoding method for StringIO if ruby 1.8
1 parent 5c4cb62 commit 314460a

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

lib/ruby-debug-ide/commands/expression_info.rb

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,7 @@ def execute
1313
total_lines = string_to_parse.count("\n") + 1
1414

1515
lexer = RubyLex.new
16-
io = StringIO.new(string_to_parse)
17-
18-
begin
19-
encoding = string_to_parse.encoding
20-
rescue
21-
encoding = 'None'
22-
end
23-
24-
# for passing to the lexer
25-
io.instance_exec(encoding) do |string_encoding|
26-
@my_encoding = string_encoding
27-
def self.encoding
28-
@my_encoding
29-
end
30-
end
31-
32-
lexer.set_input(io)
16+
lexer.set_input(create_io_reader(string_to_parse))
3317

3418
last_statement = ''
3519
last_prompt = ''
@@ -53,6 +37,21 @@ def self.encoding
5337
@printer.print_expression_info(incomplete, last_prompt, last_indent)
5438
end
5539

40+
def create_io_reader(string_to_parse)
41+
io = StringIO.new(string_to_parse)
42+
43+
if string_to_parse.respond_to?(:encoding)
44+
io.instance_exec(string_to_parse.encoding) do |string_encoding|
45+
@my_encoding = string_encoding
46+
def self.encoding
47+
@my_encoding
48+
end
49+
end
50+
end
51+
52+
io
53+
end
54+
5655
class << self
5756
def help_command
5857
"expression_info"

0 commit comments

Comments
 (0)