@custom_column = CustomColumns.configure :projects do |user, tag|
columns = ModelName.method_name(user,tag)
end
@custom_column.columns should return ["title", "description"]
CustomColumns.projects.columns should return ["title", "description"]
@custom_column1 = CustomColumns.configure :groups do |domain|
columns = ModelName.method_name(domain)
end
@custom_column1.columns should return => ["desctiption", "created_at"]
CustomColumns.groups.columns should return => ["desctiption", "created_at"]
위의 결과를 얻기 위해 아래 코드를 시도했습니다. 그러나 어떻게 다른 주장을 블록으로 전달할 수 있을지 모르겠습니다. 또는 위의 결과를 얻으려면 어떻게해야합니까?루비에서 아래의 요구 사항을 어떻게 달성 할 수 있습니까?
module CustomColumns
class Rule
attr_accessor :column_for, :columns
end
class << self
attr_accessor :rule
end
def self.configure(column_for, &block)
@column_for = column_for
@columns = block.call
end
end
처음에는 블록이 인수를 원하지만'block.call'을 사용하여 any를 yielding하지 않은 것 같습니다. 예 : 첫 번째 예제에서'user'와'tag'가 블록에 보내지고 두 번째 예제에서는'domain'이 기대됩니다. [블록에 대한 항복에 대한 간단한 자습서가 있습니다.] (http://www.tutorialspot.com/ruby/ruby_blocks.htm) 그러나 더 많은 정보가 있습니다. 그것이 어떻게 작동하는지 이해하면 이것을 이해하는 데 도움이 될 것입니다. – engineersmnky
나는 무엇을 요구하고 있습니까? 또는 나는 무엇인가 놓치고 있냐? –