Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 场地-资源处理程序-记录每个块中声明的定义_Ruby_Yard - Fatal编程技术网

Ruby 场地-资源处理程序-记录每个块中声明的定义

Ruby 场地-资源处理程序-记录每个块中声明的定义,ruby,yard,Ruby,Yard,如何为块中收集的定义编写文档?我的特殊情况是中间商,但我认为问题更为普遍,谷歌今天令人失望 例如: def manipulate_resource_list(resources) resources.each do |resource| # Provides a greeting # @return [string] Returns the greeting. def resource.hello_world 'hello, world

如何为
块中收集的定义编写文档?我的特殊情况是中间商,但我认为问题更为普遍,谷歌今天令人失望

例如:

def manipulate_resource_list(resources)
    resources.each do |resource|
      # Provides a greeting
      # @return [string] Returns the greeting.
      def resource.hello_world
        'hello, world'
      end
    resources
end
我已经走了这么远:

class ResourcesHandler < YARD::Handlers::Ruby::Base
  handles :def
  namespace_only

  def process
    if statement.method_name(true).to_sym == :manipulate_resource_list
      parse_block(statement.last.first.last.last, :owner => self.owner)
    end
  end
end
…我不得不担心当YARD遇到
def资源时,对象实例上定义的
YARD::Handlers::Ruby::MethodHandler:Undocumentable方法

注意:我想在声明附近的代码中创建文档,而不是在文件的某个远程部分


你知道如何改进我的庭院资源管理器,使其更自然吗?

好吧,我最终使用了以下方法:

class ResourcesHandler < YARD::Handlers::Ruby::Base
  handles :def
  namespace_only

  def process
    if statement.method_name(true).to_sym == :manipulate_resource_list

      # Block consists of everything in the actual `do` block
      block = statement.last.first.last.last
      block.each do | node |
        if node.type == :defs
          def_docstring = node.docstring
          def_name = node[2][0]
          object = YARD::CodeObjects::MethodObject.new(namespace, "resource.#{def_name}")
          register(object)
          object.dynamic = true
          object[:docstring] = def_docstring
          object[:group] = 'Resource Extensions'
          puts node.type
        end
      end
    end
  end
end
class-ResourcesHandler
class ResourcesHandler < YARD::Handlers::Ruby::Base
  handles :def
  namespace_only

  def process
    if statement.method_name(true).to_sym == :manipulate_resource_list

      # Block consists of everything in the actual `do` block
      block = statement.last.first.last.last
      block.each do | node |
        if node.type == :defs
          def_docstring = node.docstring
          def_name = node[2][0]
          object = YARD::CodeObjects::MethodObject.new(namespace, "resource.#{def_name}")
          register(object)
          object.dynamic = true
          object[:docstring] = def_docstring
          object[:group] = 'Resource Extensions'
          puts node.type
        end
      end
    end
  end
end