Class: Typedocs::BlockSpec
- Inherits:
-
Object
- Object
- Typedocs::BlockSpec
- Defined in:
- lib/typedocs/block_spec.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #error_message_for(block) ⇒ Object
-
#initialize(type, name) ⇒ BlockSpec
constructor
A new instance of BlockSpec.
- #to_source ⇒ Object
- #to_source_with_arrow ⇒ Object
- #valid?(block) ⇒ Boolean
Constructor Details
#initialize(type, name) ⇒ BlockSpec
Returns a new instance of BlockSpec.
3 4 5 6 7 |
# File 'lib/typedocs/block_spec.rb', line 3 def initialize(type, name) raise ArgumentError unless [:req, :opt, :none].include?(type) @name = name @type = type end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/typedocs/block_spec.rb', line 8 def name @name end |
Instance Method Details
#error_message_for(block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/typedocs/block_spec.rb', line 19 def (block) raise ArgumentError if valid?(block) case @type when :req "Block not given" when :none "Block not allowed" else raise 'maybe typedocs bug' end end |
#to_source ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/typedocs/block_spec.rb', line 30 def to_source n = name case @type when :req "&#{n}" when :opt "?&#{n}" when :none '' else raise "Invalid type: #{@type}" end end |
#to_source_with_arrow ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/typedocs/block_spec.rb', line 43 def to_source_with_arrow if @type == :none '' else "#{to_source} -> " end end |
#valid?(block) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/typedocs/block_spec.rb', line 9 def valid?(block) case block when nil return @type == :opt || @type == :none when Proc return @type == :opt || @type == :req else raise 'maybe typedocs bug' end end |