Class: Ev3dev::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/ev3dev/device.rb

Direct Known Subclasses

Motor, Sensor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device_path) ⇒ Device

Returns a new instance of Device.



5
6
7
# File 'lib/ev3dev/device.rb', line 5

def initialize(device_path)
  @device_path = device_path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ev3dev/device.rb', line 9

def method_missing(name, *args, &block)
  raise "no device connected" if @device_path.nil?
  param = File.join @device_path, name.to_s
  raise "no such attribute: #{param}" unless File.exist? param
  if args.first.nil?
    IO.read(param).strip
  else
    IO.write param, args.first.to_s
    self
  end
end

Instance Attribute Details

#device_pathObject (readonly)

Returns the value of attribute device_path.



3
4
5
# File 'lib/ev3dev/device.rb', line 3

def device_path
  @device_path
end