Module: RubyScribe::SexpHelpers::InstanceMethods
- Defined in:
- lib/ruby_scribe/sexp_helpers.rb
Instance Method Summary collapse
- #arguments ⇒ Object
- #block ⇒ Object
- #body ⇒ Object
- #call!(name, arguments = nil, body = nil) ⇒ Object
- #call?(name = nil, options = {}) ⇒ Boolean
- #call_with_block?(name = nil, options = {}) ⇒ Boolean
- #call_without_block?(name = nil, options = {}) ⇒ Boolean
- #case? ⇒ Boolean
- #class?(name = nil, options = {}) ⇒ Boolean
- #conditional?(options = {}) ⇒ Boolean
- #kind ⇒ Object
- #method?(name = nil) ⇒ Boolean
- #module?(name = nil) ⇒ Boolean
- #name ⇒ Object
- #receiver ⇒ Object
- #rescue? ⇒ Boolean
- #to_args ⇒ Object
Instance Method Details
#arguments ⇒ Object
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 139 def arguments case kind when :call, :defs body[2] when :defn, :iter body[1] else nil end end |
#block ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 154 def block case kind when :defn strip_scope_wrapper(body[2]) when :defs strip_scope_wrapper(body[3]) when :class strip_scope_wrapper(body[2]) when :module strip_scope_wrapper(body[1]) else nil end end |
#body ⇒ Object
113 114 115 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 113 def body sexp_body end |
#call!(name, arguments = nil, body = nil) ⇒ Object
169 170 171 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 169 def call!(name, arguments = nil, body = nil) Sexp.call_on!(self, name, arguments, body) end |
#call?(name = nil, options = {}) ⇒ Boolean
188 189 190 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 188 def call?(name = nil, = {}) call_without_block?(name, ) || call_with_block?(name, ) end |
#call_with_block?(name = nil, options = {}) ⇒ Boolean
199 200 201 202 203 204 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 199 def call_with_block?(name = nil, = {}) kind == :iter && body[0] && body[0].kind == :call && (name.nil? || match_expression(body[0].name, name)) && ([:arguments].nil? || match_arguments_expression(body[0], [:arguments])) && ([:block].nil? || match_arguments_expression(self, [:block])) end |
#call_without_block?(name = nil, options = {}) ⇒ Boolean
192 193 194 195 196 197 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 192 def call_without_block?(name = nil, = {}) kind == :call && (name.nil? || match_expression(body[1], name)) && ([:arguments].nil? || match_arguments_expression(self, [:arguments])) && (![:block]) end |
#case? ⇒ Boolean
215 216 217 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 215 def case? kind == :case end |
#class?(name = nil, options = {}) ⇒ Boolean
178 179 180 181 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 178 def class?(name = nil, = {}) kind == :class && (name.nil? || match_expression(body[0], name)) end |
#conditional?(options = {}) ⇒ Boolean
210 211 212 213 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 210 def conditional?( = {}) kind == :if && ([:type].nil? || match_conditional_type(self, [:type])) end |
#kind ⇒ Object
109 110 111 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 109 def kind sexp_type.to_sym end |
#method?(name = nil) ⇒ Boolean
183 184 185 186 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 183 def method?(name = nil) (kind == :defn && (name.nil? || match_expression(body[0], name))) || (kind == :defs && (name.nil? || match_expression(body[1], name))) end |
#module?(name = nil) ⇒ Boolean
173 174 175 176 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 173 def module?(name = nil) kind == :module && (name.nil? || match_expression(body[0], name)) end |
#name ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 117 def name case kind when :call body[1] when :lasgn, :iasgn, :class, :module body[0] when :iter body[0].name else nil end end |
#receiver ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 130 def receiver case kind when :call body[0] else nil end end |
#rescue? ⇒ Boolean
206 207 208 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 206 def rescue? kind == :rescue end |
#to_args ⇒ Object
150 151 152 |
# File 'lib/ruby_scribe/sexp_helpers.rb', line 150 def to_args emit_as_args_array(arguments) end |