Class: Yast::FunRef

Inherits:
Object
  • Object
show all
Defined in:
src/ruby/yast/fun_ref.rb,
src/ruby/yast/ops.rb,
src/ruby/yast/yast.rb,
src/ruby/yast/builtins.rb

Overview

Provides wrapper to pass reference to function. It is used by component system to allow passing reference to function. Class is immutable

Examples:

pass function as reference

def a
  return 5
end

ref_a = FunRef.new method(:a), "integer()"

pass reference to lambda

ref_lambda = FunRef.new lambda{ return 5 }, "integer()"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(met, signature) ⇒ FunRef



21
22
23
24
25
26
27
28
29
# File 'src/ruby/yast/fun_ref.rb', line 21

def initialize(met, signature)
  @remote_method = met
  raise "invalid argument #{met.inspect}" unless met.respond_to? :call

  # expand signature to containt full spec of lists and maps
  signature = signature.gsub(/map(\s*([^<\s]|$))/, "map<any,any>\\1")
  signature = signature.gsub(/list(\s*([^<\s]|$))/, "list<any>\\1")
  @signature = signature
end

Instance Attribute Details

#remote_methodObject (readonly)

reference to method responds to method call



19
20
21
# File 'src/ruby/yast/fun_ref.rb', line 19

def remote_method
  @remote_method
end

#signatureObject (readonly)

Signature recognized by YCPType



17
18
19
# File 'src/ruby/yast/fun_ref.rb', line 17

def signature
  @signature
end

Instance Method Details

#call(*args) ⇒ Object

Forwards call to reference method



32
33
34
# File 'src/ruby/yast/fun_ref.rb', line 32

def call(*args)
  @remote_method.call(*args)
end