Module: RubyScribe::SexpHelpers::ClassMethods
- Defined in:
- lib/ruby_scribe/sexp_helpers.rb
Instance Method Summary collapse
- #call!(name, arguments = nil, body = nil) ⇒ Object
- #call_args!(arguments = nil) ⇒ Object
- #call_on!(receiver, name, arguments = nil, body = nil) ⇒ Object
- #class!(name, extends = nil, body = nil) ⇒ Object
- #method!(name, arguments = nil, body = nil) ⇒ Object
- #method_args!(arguments = nil) ⇒ Object
- #method_body!(body = nil) ⇒ Object
- #method_on!(on, name, arguments = nil, body = nil) ⇒ Object
- #module!(name, body = nil) ⇒ Object
Instance Method Details
#call!(name, arguments = nil, body = nil) ⇒ Object
50 51 52 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 50 def call!(name, arguments = nil, body = nil) call_on!(nil, name.to_sym, arguments, body) end |
#call_args!(arguments = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 58 def call_args!(arguments = nil) arguments ||= [] if arguments.is_a?(Sexp) && arguments.kind == :arglist arguments elsif arguments.is_a?(Sexp) s(:arglist, arguments) elsif arguments.is_a?(Array) s(*([:arglist] + arguments)) else s(:arglist) end end |
#call_on!(receiver, name, arguments = nil, body = nil) ⇒ Object
54 55 56 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 54 def call_on!(receiver, name, arguments = nil, body = nil) s(:call, receiver, name.to_sym, call_args!(arguments)) end |
#class!(name, extends = nil, body = nil) ⇒ Object
15 16 17 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 15 def class!(name, extends = nil, body = nil) s(:class, generate_module_or_class_name(name), generate_class_extend_from(extends), ensure_scope_wrapped(body)) end |
#method!(name, arguments = nil, body = nil) ⇒ Object
19 20 21 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 19 def method!(name, arguments = nil, body = nil) s(:defn, name.to_sym, method_args!(arguments), method_body!(body)) end |
#method_args!(arguments = nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 27 def method_args!(arguments = nil) arguments ||= [] = arguments. s(*([:args] + arguments.map(&:to_sym))).tap do |args| args.push s(*([:block] + .map {|k, v| s(:lasgn, k.to_sym, v) })) if && !.empty? end end |
#method_body!(body = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 36 def method_body!(body = nil) if body.is_a?(Sexp) && body.kind == :scope body elsif body.is_a?(Sexp) && body.kind == :block ensure_scope_wrapped(body) elsif body.is_a?(Sexp) method_body!(s(:block, body)) elsif body.is_a?(Array) method_body!(s(*([:block] + body))) else method_body!(s(:block, s(:nil))) end end |
#method_on!(on, name, arguments = nil, body = nil) ⇒ Object
23 24 25 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 23 def method_on!(on, name, arguments = nil, body = nil) s(:defs, on, name.to_sym, method_args!(arguments), method_body!(body)) end |
#module!(name, body = nil) ⇒ Object
11 12 13 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 11 def module!(name, body = nil) s(:module, generate_module_or_class_name(name), ensure_scope_wrapped(body)) end |