Class: C::Node::Field
- Inherits:
-
Object
- Object
- C::Node::Field
- Defined in:
- lib/cast/node.rb
Overview
Instance Attribute Summary collapse
-
#child ⇒ Object
writeonly
True if this field is a child field, false otherwise.
-
#default ⇒ Object
Returns the value of attribute default.
-
#index ⇒ Object
Returns the value of attribute index.
-
#init_key ⇒ Object
Returns the value of attribute init_key.
-
#reader ⇒ Object
Returns the value of attribute reader.
-
#var ⇒ Object
Returns the value of attribute var.
-
#writer ⇒ Object
Returns the value of attribute writer.
Instance Method Summary collapse
- #child? ⇒ Boolean
-
#initialize(name, default) ⇒ Field
constructor
A new instance of Field.
-
#make_default ⇒ Object
Create a default value for this field.
Constructor Details
#initialize(name, default) ⇒ Field
Returns a new instance of Field.
702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/cast/node.rb', line 702 def initialize(name, default) name = name.to_s @child = false @reader = name.to_sym @default = default if name[-1] == ?? then name[-1] = '' end @init_key = name.to_sym @var = "@#{name}".to_sym @writer = "#{name}=".to_sym end |
Instance Attribute Details
#child=(value) ⇒ Object (writeonly)
True if this field is a child field, false otherwise.
684 685 686 |
# File 'lib/cast/node.rb', line 684 def child=(value) @child = value end |
#default ⇒ Object
Returns the value of attribute default.
678 679 680 |
# File 'lib/cast/node.rb', line 678 def default @default end |
#index ⇒ Object
Returns the value of attribute index.
678 679 680 |
# File 'lib/cast/node.rb', line 678 def index @index end |
#init_key ⇒ Object
Returns the value of attribute init_key.
678 679 680 |
# File 'lib/cast/node.rb', line 678 def init_key @init_key end |
#reader ⇒ Object
Returns the value of attribute reader.
678 679 680 |
# File 'lib/cast/node.rb', line 678 def reader @reader end |
#var ⇒ Object
Returns the value of attribute var.
678 679 680 |
# File 'lib/cast/node.rb', line 678 def var @var end |
#writer ⇒ Object
Returns the value of attribute writer.
678 679 680 |
# File 'lib/cast/node.rb', line 678 def writer @writer end |
Instance Method Details
#child? ⇒ Boolean
685 686 687 |
# File 'lib/cast/node.rb', line 685 def child? @child end |
#make_default ⇒ Object
Create a default value for this field. This differs from #default in that if it's a Proc, it is called and the result returned.
694 695 696 697 698 699 700 |
# File 'lib/cast/node.rb', line 694 def make_default if @default.respond_to? :call @default.call else @default end end |