Class: CIM::Method

Inherits:
ClassFeature show all
Defined in:
lib/cim/method.rb

Overview

A Method defines a function member of a Class.

For data members, see Property.

Instance Attribute Summary

Attributes inherited from ClassFeature

#type

Attributes inherited from NamedElement

#name, #qualifiers

Instance Method Summary collapse

Methods inherited from ClassFeature

#property?, #reference?

Methods inherited from NamedElement

#<<, #include?

Constructor Details

#initialize(type, name, qualifiers = nil, parameters = nil) ⇒ Method

Create a Method with return type (Type) and name (String), optional Qualifiers and parameters (Property)

call-seq:

Method.new(:boolean, "do_something")
Method.new(:boolean, "do_something", qualifiers)
Method.new(:boolean, "do_something", qualifiers, parameters)


25
26
27
28
# File 'lib/cim/method.rb', line 25

def initialize type, name, qualifiers = nil, parameters = nil
  @parameters = parameters
  super type,name,qualifiers
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Check for qualifiers

# check for existance
method.qualifier? -> true or false

# check value
method.description -> String or nil


57
58
59
60
61
62
63
# File 'lib/cim/method.rb', line 57

def method_missing name, *args
  if name.to_s[-1,1] == "?"
    @qualifiers && @qualifiers.include?(name.to_s[0...-1])
  else
    (@qualifiers[name].value || @qualifiers[name].declaration.default) rescue nil
  end
end

Instance Method Details

#method?Boolean

Makes a Method recognizable in the set of Class features.

Returns:

  • (Boolean)


38
39
40
# File 'lib/cim/method.rb', line 38

def method?
  true
end

#parametersObject

parameters accessor



32
33
34
# File 'lib/cim/method.rb', line 32

def parameters
  @parameters || []
end

#to_sObject

returns a string representation in MOF syntax format



44
45
46
47
# File 'lib/cim/method.rb', line 44

def to_s
  p = parameters.join(", ")
  "#{super}(#{p})"
end