logger = Logger.new(STDERR)
table_name = ENV['ec2_information'].split('/')[1]
discovery = Ec2_ddb_discovery.new(logger:, table:)
discovery.scan_ddb_table
discovery.collect_stale_items.each { |item|
答案 0 :(得分:1)
正如max pleaner在其评论中提到的那样,您可以使用instance_eval,或者,如果需要传递参数,则可以使用instance_exec。 这些通常用于创建DSLs,但我们也可以这样。
class Foo
def bar_one
puts "hello from bar_one"
end
def bar_two
puts "hello from bar_two"
end
def bar_three(arg)
puts "hello from bar_three with #{arg}"
end
end
Foo.new.instance_eval do
bar_one
bar_two
bar_three("local_argument")
end
Foo.new.instance_exec("passed_argument") do |arg|
bar_one
bar_two
bar_three(arg)
end