Class: Hirb::Helpers::ParentChildTree

### Home Classes Methods

### In Files

- lib/hirb/helpers/parent_child_tree.rb

### Parent

Hirb::Helpers::Tree

### Methods

- ::render

### Files

- LICENSE.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Hirb
- Hirb::Console
- Hirb::DynamicView
- Hirb::Formatter
- Hirb::Helpers
- Hirb::Helpers::AutoTable
- Hirb::Helpers::ObjectTable
- Hirb::Helpers::ParentChildTree
- Hirb::Helpers::Table
- Hirb::Helpers::Table::Filters
- Hirb::Helpers::Table::Resizer
- Hirb::Helpers::Table::TooManyFieldsForWidthError
- Hirb::Helpers::Tree
- Hirb::Helpers::Tree::Node
- Hirb::Helpers::Tree::Node::MissingLevelError
- Hirb::Helpers::Tree::Node::MissingValueError
- Hirb::Helpers::Tree::ParentlessNodeError
- Hirb::Helpers::VerticalTable
- Hirb::Menu
- Hirb::Menu::Error
- Hirb::ObjectMethods
- Hirb::Pager
- Hirb::String
- Hirb::Util
- Hirb::View
- Hirb::Views

No matching classes.

# Hirb::Helpers::ParentChildTree

### Public Class Methods

render(root_node, options={}) click to toggle source

Starting with the given node, this builds a tree by recursively calling a children method. Takes same options as Hirb::Helper::Table.render with some additional ones below.

#### Options:

:value_method

  Method or proc to call to display as a node’s value. If not given, uses :name if node responds to :name or defaults to :object_id.

:children_method

  Method or proc to call to obtain a node’s children. Default is :children.

    # File lib/hirb/helpers/parent_child_tree.rb, line 9
    def render(root_node, options={})
      value_method = options[:value_method] || (root_node.respond_to?(:name) ? :name : :object_id)
      @value_method = value_method.is_a?(Proc) ? value_method : lambda {|n| n.send(value_method) }
      children_method = options[:children_method] || :children
      @children_method = children_method.is_a?(Proc) ? children_method : lambda {|n| n.send(children_method)}
      @nodes = []
      build_node(root_node, 0)
      super(@nodes, options)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.