Method: AbstractBuilder#method_missing

Defined in:
lib/abstract_builder.rb

#method_missing(*args, &block) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/abstract_builder.rb', line 101

def method_missing(*args, &block)
  if args.length == 2 && block
    array!(args[0], args[1], &block)
  elsif args.length == 1 && block
    block!(args[0], &block)
  elsif args.length == 2
    set!(args[0], args[1])
  else
    raise ArgumentError, <<~EOF.chomp
      Expected 1 argument without a block, 0 arguments with a block or 1 argument with a block.

      This is `AbstractBuilder#set!', `AbstractBuilder#block!' or `AbstractBuilder#array!' signatures, example:

          builder.content post.content

          builder.meta do |meta_builder|
            meta_builder.hashtags post.hashtags
          end

          builder.comments post.comments do |comment_builder, comment|
            comment_builder.content comment.content
          end

      Received `#{args[0]}' with #{args.length - 1} argument#{'s' if args.length > 2} #{block ? "with a block" : "without a block"}.
    EOF
  end
end