Module: Native::Helpers
- Defined in:
- opal/stdlib/native.rb
Instance Method Summary collapse
-
#alias_native(new, old = new, as: nil) ⇒ Object
Exposes a native JavaScript method to Ruby.
- #native_accessor(*names) ⇒ Object
- #native_reader(*names) ⇒ Object
- #native_writer(*names) ⇒ Object
Instance Method Details
#alias_native(new, old = new, as: nil) ⇒ Object
Exposes a native JavaScript method to Ruby
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'opal/stdlib/native.rb', line 146 def alias_native(new, old = new, as: nil) if old.end_with? '=' define_method new do |value| `#{@native}[#{old[0..-2]}] = #{Native.convert(value)}` value end elsif as define_method new do |*args, &block| value = Native.call(@native, old, *args, &block) if value as.new(value.to_n) end end else define_method new do |*args, &block| Native.call(@native, old, *args, &block) end end end |
#native_accessor(*names) ⇒ Object
[View source]
183 184 185 186 |
# File 'opal/stdlib/native.rb', line 183 def native_accessor(*names) native_reader(*names) native_writer(*names) end |
#native_reader(*names) ⇒ Object
[View source]
167 168 169 170 171 172 173 |
# File 'opal/stdlib/native.rb', line 167 def native_reader(*names) names.each do |name| define_method name do Native(`#{@native}[name]`) end end end |
#native_writer(*names) ⇒ Object
[View source]
175 176 177 178 179 180 181 |
# File 'opal/stdlib/native.rb', line 175 def native_writer(*names) names.each do |name| define_method "#{name}=" do |value| Native(`#{@native}[name] = value`) end end end |