Class: AutoC::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/autoc/function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, constant: false, reference: false) ⇒ Value

Returns a new instance of Value.



26
27
28
29
30
# File 'lib/autoc/function.rb', line 26

def initialize(type, constant: false, reference: false)
  @type = type
  @constant = constant
  @reference = reference
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



16
17
18
# File 'lib/autoc/function.rb', line 16

def type
  @type
end

Instance Method Details

#call(value) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/autoc/function.rb', line 39

def call(value)
  value = value.to_s
  if reference?
    # Manually collapse references &*xyz -> xyz for the sake of source code readability
    value[0] =='*' ? value[1..-1] : "&#{value}"
  else
    value
  end
end

#constant?Boolean

Returns:

  • (Boolean)


22
# File 'lib/autoc/function.rb', line 22

def constant? = @constant == true

#reference?Boolean

Returns:

  • (Boolean)


24
# File 'lib/autoc/function.rb', line 24

def reference? = @reference == true

#signatureObject



34
35
36
37
# File 'lib/autoc/function.rb', line 34

def signature
  _ = reference? ? "#{type.signature}*" : type.signature
  constant? ? "const #{_}" : _
end

#to_sObject



32
# File 'lib/autoc/function.rb', line 32

def to_s = signature

#to_typeObject



18
# File 'lib/autoc/function.rb', line 18

def to_type = type

#to_valueObject



20
# File 'lib/autoc/function.rb', line 20

def to_value = self