Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3125a6c0f762
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8e8b615c4a45
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Nov 11, 2014

  1. clean up syntax in enum.rb

    kodnin committed Nov 11, 2014
    Copy the full SHA
    eb6696e View commit details
  2. Merge pull request #3196 from kodnin/clean-up-enum.rb

    clean up syntax in enum.rb
    Yorick Peterse committed Nov 11, 2014
    Copy the full SHA
    8e8b615 View commit details
Showing with 44 additions and 49 deletions.
  1. +2 −1 AUTHORS
  2. +42 −48 kernel/platform/enum.rb
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -59,11 +59,12 @@
- Daniel Lucraft: { irc: dan_lucraft }
- Daniel Luz:
- David Altenburg:
- David Boot { github: kodnin, twitter: kodnin, email: kodnin@gmail.com }
- David Salamon:
- David Waite: { irc: ddubs }
- David Whittington: { irc: djwhitt }
- David Yip:
- Davor Babic: { irc: davorb, github: davorb, email: davor@davor.se }
- Davor Babic: { irc: davorb, github: davorb, email: davor@davor.se }
- Defn:
- Dirkjan Bussink: { irc: dbussink }
- Drew Olson:
90 changes: 42 additions & 48 deletions kernel/platform/enum.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,55 @@
module Rubinius
module FFI

# Represents a C enum.
class Enum

attr_reader :tag
attr_reader :kv_map

def initialize(info, tag=nil)
@tag = tag
@kv_map = Hash.new

unless info.nil?
last_cst = nil
value = 0
info.each do |i|
case i
when Symbol
@kv_map[i] = value
last_cst = i
value += 1
when Integer
@kv_map[last_cst] = i
value = i+1
module FFI
# Represents a C enum.
class Enum
attr_reader :tag
attr_reader :kv_map

def initialize(info, tag=nil)
@tag = tag
@kv_map = Hash.new

unless info.nil?
last_cst = nil
value = 0
info.each do |i|
case i
when Symbol
@kv_map[i] = value
last_cst = i
value += 1
when Integer
@kv_map[last_cst] = i
value = i + 1
end
end

end

end

end

def inspect
"#<%s:0x%x %s=>%s>" % [self.class,self.object_id,@tag,@kv_map.inspect]
end
def inspect
"#<%s:0x%x %s=>%s>" % [self.class, self.object_id, @tag, @kv_map.inspect]
end

def anonym?
@tag.nil?
end
def anonym?
@tag.nil?
end

def values
@kv_map.values
end
def values
@kv_map.values
end

def symbols
@kv_map.keys
end
def symbols
@kv_map.keys
end

def [](sym)
@kv_map[sym]
end
def [](sym)
@kv_map[sym]
end

def symbol(value)
key,val = @kv_map.detect { |key,val| val==value }
return key
def symbol(value)
key, val = @kv_map.detect { |key, val| val == value }
key
end
end

end
end
end