我的印象是,精炼不在Ruby的通常继承模式之内;在优化内覆盖一个方法,使用细化替换所有代码的原始方法。 但后来,我想这个实验super,并且看起来被覆盖的方法被调用: class MyClass
def my_instance_method
puts "MyClass#my_instance_method"
end
end
module MyRefinement
我正在寻找替代移动演示文稿的数据,以桌面形式显示为表格。我看到一个很好的例子,看起来像这样: account____________________ 1234567
due date_______________ 10-NOV-2016
balance_____________________$100.00
note_____description and stuff here
我发现的
看来,to_proc不上改进定义的方法工作: module ArrayExtensions
refine Array do
def sum
reduce(0, :+)
end
end
end
using ArrayExtensions
puts [[1, 2, 3]].map { |array| array.sum } # => 6
我正在浏览Facets API并选择一些方法将其包含在我的优化兼容补丁库中。 我碰到了一个试图修补内核的障碍。这是一个模块,而其他的东西我已经修补一直班(字符串,阵列等) 这里是不能不能使用我的核心类标准的方法提炼证明: module Patch
refine Kernel do
def patched?
true
end
end
end
在Metaprogramming Ruby 2的 “加细” 一节,我发现了下面的一段Ruby代码: class MyClass
def my_method
"original my_method()"
end
def another_method
my_method
end
end
module MyClassRefinemen