Skip to content

Commit

Permalink
Added our own Tuple class for specifying tuple data in Ruby.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jan 15, 2010
1 parent 42ebbe6 commit 21ce49b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ lib/bert.rb
lib/bert/types.rb
lib/bert/errno.rb
lib/bert/ffi.rb
lib/bert/extensions.rb
lib/bert/extensions/tuple.rb
lib/bert/atom_value.rb
lib/bert/string_value.rb
lib/bert/bin_value.rb
Expand Down
16 changes: 14 additions & 2 deletions lib/bert/data.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'bert/extensions/tuple'
require 'bert/data_values'

require 'ffi'
Expand Down Expand Up @@ -144,10 +145,21 @@ def Data.from_ruby(obj)
when Hash
Data.create_dict()
# TODO: append the elements of the Hash to the dict
when Tuple
data = Data.create_tuple(obj.length)

obj.each_with_index do |element,index|
data.tuple[index] = Data.from_ruby(element)
end

return data
when Array
data = Data.create_list()

obj.each { |element| data.list << Data.from_ruby(element) }
obj.each do |element|
data.list << Data.from_ruby(element)
end

return data
when Regexp
Data.create_regex(obj.source,obj.options)
Expand Down Expand Up @@ -233,7 +245,7 @@ def to_ruby
when :string
self.string.to_s
when :tuple
self.tuple.to_a
::Tuple.new(self.tuple.to_a)
when :list
self.list.to_a
when :dict
Expand Down
1 change: 1 addition & 0 deletions lib/bert/extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'bert/extensions/tuple'
7 changes: 7 additions & 0 deletions lib/bert/extensions/tuple.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Tuple < Array

def inspect
'{' + self.map { |elem| elem.inspect }.join(', ') + '}'
end

end

0 comments on commit 21ce49b

Please sign in to comment.