Class: RVM::Functions::Regmatch

Inherits:
Function
  • Object
show all
Defined in:
lib/rvm/functions/string/regmatch.rb

Class Method Summary collapse

Methods inherited from Function

call, execargs, method_missing

Methods included from Plugin

#helper, #included, #plugin_host, #plugin_id, #register_for

Class Method Details

.data_typeObject



27
28
29
# File 'lib/rvm/functions/string/regmatch.rb', line 27

def data_type
  :boolean
end

.execute(params, env) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rvm/functions/string/regmatch.rb', line 5

def execute params, env
  if params.length == 2
    str = params[0]
    regexp = params[1].to_s
    begin
      regexp = Regexp.new(regexp)
    rescue
      return RVM::Classes[:error].new(1,"INVALID REGULAR EXPRESSION")
    end
    if regexp.match(str)
      RVM::Classes[:boolean].new(true)
    else
      RVM::Classes[:boolean].new(false)
    end
  else
    RVM::Classes[:error].new(1,"FUNCTION (#{self.class.to_s}) EXPECTS 2 ARGUMENTS BUT GOT #{params.length}")     
  end
end

.signatureObject



23
24
25
# File 'lib/rvm/functions/string/regmatch.rb', line 23

def signature
  [:string, :string] # adjust the signature here
end