Module: RubyScribe::SexpHelpers::InstanceMethods

Defined in:
lib/ruby_scribe/sexp_helpers.rb

Instance Method Summary collapse

Instance Method Details

#argumentsObject



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

#blockObject



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

#bodyObject



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

Returns:

  • (Boolean)


188
189
190
# File 'lib/ruby_scribe/sexp_helpers.rb', line 188

def call?(name = nil, options = {})
  call_without_block?(name, options) || call_with_block?(name, options)
end

#call_with_block?(name = nil, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


199
200
201
202
203
204
# File 'lib/ruby_scribe/sexp_helpers.rb', line 199

def call_with_block?(name = nil, options = {})
  kind == :iter && body[0] && body[0].kind == :call &&
  (name.nil? || match_expression(body[0].name, name)) &&
  (options[:arguments].nil? || match_arguments_expression(body[0], options[:arguments])) &&
  (options[:block].nil? || match_arguments_expression(self, options[:block]))
end

#call_without_block?(name = nil, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


192
193
194
195
196
197
# File 'lib/ruby_scribe/sexp_helpers.rb', line 192

def call_without_block?(name = nil, options = {})
  kind == :call && 
  (name.nil? || match_expression(body[1], name)) &&
  (options[:arguments].nil? || match_arguments_expression(self, options[:arguments])) &&
  (!options[:block])
end

#case?Boolean

Returns:

  • (Boolean)


215
216
217
# File 'lib/ruby_scribe/sexp_helpers.rb', line 215

def case?
  kind == :case
end

#class?(name = nil, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


178
179
180
181
# File 'lib/ruby_scribe/sexp_helpers.rb', line 178

def class?(name = nil, options = {})
  kind == :class && 
  (name.nil? || match_expression(body[0], name))
end

#conditional?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


210
211
212
213
# File 'lib/ruby_scribe/sexp_helpers.rb', line 210

def conditional?(options = {})
  kind == :if && 
  (options[:type].nil? || match_conditional_type(self, options[:type]))
end

#kindObject



109
110
111
# File 'lib/ruby_scribe/sexp_helpers.rb', line 109

def kind
  sexp_type.to_sym
end

#method?(name = nil) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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

#nameObject



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

#receiverObject



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

Returns:

  • (Boolean)


206
207
208
# File 'lib/ruby_scribe/sexp_helpers.rb', line 206

def rescue?
  kind == :rescue
end

#to_argsObject



150
151
152
# File 'lib/ruby_scribe/sexp_helpers.rb', line 150

def to_args
  emit_as_args_array(arguments)
end