From 221c264edf04c33f0ec670523cd38d82681cbd65 Mon Sep 17 00:00:00 2001 From: Aleksey Date: Sun, 16 Sep 2018 17:29:52 +0500 Subject: [PATCH] refactoring: stand-in class methods against of meta-code --- lib/roo/base.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/roo/base.rb b/lib/roo/base.rb index 89566a88..c96bbb49 100644 --- a/lib/roo/base.rb +++ b/lib/roo/base.rb @@ -115,13 +115,12 @@ def collect_last_row_col_for_sheet(sheet) { first_row: first_row, first_column: first_column, last_row: last_row, last_column: last_column } end - %w(first_row last_row first_column last_column).each do |key| - class_eval <<-EOS, __FILE__, __LINE__ + 1 - def #{key}(sheet = default_sheet) # def first_row(sheet = default_sheet) - read_cells(sheet) # read_cells(sheet) - @#{key}[sheet] ||= first_last_row_col_for_sheet(sheet)[:#{key}] # @first_row[sheet] ||= first_last_row_col_for_sheet(sheet)[:first_row] - end # end - EOS + %i(first_row last_row first_column last_column).each do |key| + ivar = "@#{key}".to_sym + define_method(key) do |sheet = default_sheet| + read_cells(sheet) + instance_variable_get(ivar)[sheet] ||= first_last_row_col_for_sheet(sheet)[key] + end end def inspect