Module: Native::Helpers

Defined in:
opal/stdlib/native.rb

Instance Method Summary collapse

Instance Method Details

#alias_native(new, old = new, options = {}) ⇒ Object


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'opal/stdlib/native.rb', line 68

def alias_native(new, old = new, options = {})
  if old.end_with? ?=
    define_method new do |value|
      `#@native[#{old[0 .. -2]}] = #{Native.convert(value)}`

      value
    end
  else
    if as = options[:as]
      define_method new do |*args, &block|
        if value = Native.call(@native, old, *args, &block)
          as.new(value.to_n)
        end
      end
    else
      define_method new do |*args, &block|
        Native.call(@native, old, *args, &block)
      end
    end
  end
end

#native_accessor(*names) ⇒ Object


106
107
108
109
# File 'opal/stdlib/native.rb', line 106

def native_accessor(*names)
  native_reader(*names)
  native_writer(*names)
end

#native_reader(*names) ⇒ Object


90
91
92
93
94
95
96
# File 'opal/stdlib/native.rb', line 90

def native_reader(*names)
  names.each {|name|
    define_method name do
      Native(`#@native[name]`)
    end
  }
end

#native_writer(*names) ⇒ Object


98
99
100
101
102
103
104
# File 'opal/stdlib/native.rb', line 98

def native_writer(*names)
  names.each {|name|
    define_method "#{name}=" do |value|
      Native(`#@native[name] = value`)
    end
  }
end