1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Code: simplify .from_file class method

1. Use a temporary variable to hold code;
2. Instantiate `Pry::Code` only in one place;
3. Refactor reading from a file (a credit flies to John Mair).

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
This commit is contained in:
Kyrylo Silin 2013-01-07 17:33:40 +02:00
parent 8779d50fd9
commit 28bdf098ce

View file

@ -59,11 +59,12 @@ class Pry
# @param [Symbol] code_type The type of code the file contains.
# @return [Code]
def from_file(filename, code_type = type_from_filename(filename))
if filename == Pry.eval_path
new(Pry.line_buffer.drop(1), 1, code_type)
else
File.open(abs_path(filename), 'r') { |f| new(f, 1, code_type) }
end
code = if filename == Pry.eval_path
Pry.line_buffer.drop(1)
else
File.read(abs_path(filename))
end
new(code, 1, code_type)
end
# Instantiate a `Code` object containing code extracted from a