在我的lib文件夹中,我有billede.rb:
class Billede
require 'RMagick'
#some code that creates a watermark for a image
image.write(out)
end
Run Code Online (Sandbox Code Playgroud)
我如何致电/激活课程?是将它更改为Rake任务的唯一方法吗?
你不能直接打电话给班级.你必须在该类上调用一个方法.例如:
class Billede
def self.foobar
# some kind of code here...
end
end
Run Code Online (Sandbox Code Playgroud)
然后你可以通过它来调用它 Billede.foobar
也许你应该在尝试做更复杂的事情之前阅读一些关于基本ruby语法的文档(比如用Rmagick操作图像).
| 归档时间: |
|
| 查看次数: |
103 次 |
| 最近记录: |