Class: C::Node::Field
- Inherits:
-
Object
- Object
- C::Node::Field
- Defined in:
- lib/casty/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.
703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'lib/casty/node.rb', line 703 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.
685 686 687 |
# File 'lib/casty/node.rb', line 685 def child=(value) @child = value end |
#default ⇒ Object
Returns the value of attribute default.
679 680 681 |
# File 'lib/casty/node.rb', line 679 def default @default end |
#index ⇒ Object
Returns the value of attribute index.
679 680 681 |
# File 'lib/casty/node.rb', line 679 def index @index end |
#init_key ⇒ Object
Returns the value of attribute init_key.
679 680 681 |
# File 'lib/casty/node.rb', line 679 def init_key @init_key end |
#reader ⇒ Object
Returns the value of attribute reader.
679 680 681 |
# File 'lib/casty/node.rb', line 679 def reader @reader end |
#var ⇒ Object
Returns the value of attribute var.
679 680 681 |
# File 'lib/casty/node.rb', line 679 def var @var end |
#writer ⇒ Object
Returns the value of attribute writer.
679 680 681 |
# File 'lib/casty/node.rb', line 679 def writer @writer end |
Instance Method Details
#child? ⇒ Boolean
686 687 688 |
# File 'lib/casty/node.rb', line 686 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.
695 696 697 698 699 700 701 |
# File 'lib/casty/node.rb', line 695 def make_default if @default.respond_to? :call @default.call else @default end end |