Class: RubDev::List
Instance Method Summary collapse
- #[](name) ⇒ Object
- #by_name(name) ⇒ Object
- #each(&blk) ⇒ Object
-
#initialize(list) ⇒ List
constructor
A new instance of List.
- #name ⇒ Object
- #next ⇒ Object
- #rewind ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(list) ⇒ List
Returns a new instance of List.
26 27 28 29 |
# File 'lib/rubdev/list.rb', line 26 def initialize (list) @top = list rewind end |
Instance Method Details
#[](name) ⇒ Object
54 55 56 |
# File 'lib/rubdev/list.rb', line 54 def [] (name) by_name(name).value end |
#by_name(name) ⇒ Object
41 42 43 44 |
# File 'lib/rubdev/list.rb', line 41 def by_name (name) RubDev::C.udev_list_entry_get_by_name(@pointer, name) self end |
#each(&blk) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rubdev/list.rb', line 58 def each(&blk) array = [] pointer = @pointer rewind unless @pointer.null? blk.call(name, value) if blk array << [name, value] self.next end @pointer = pointer blk ? array : Enumerator.new(array) end |
#name ⇒ Object
46 47 48 |
# File 'lib/rubdev/list.rb', line 46 def name RubDev::C.udev_list_entry_get_name(@pointer) end |
#next ⇒ Object
36 37 38 39 |
# File 'lib/rubdev/list.rb', line 36 def next @pointer = RubDev::C.udev_list_entry_get_next(@pointer) self end |
#rewind ⇒ Object
31 32 33 34 |
# File 'lib/rubdev/list.rb', line 31 def rewind @pointer = @top self end |