Class: OodSupport::Group
- Inherits:
-
Object
- Object
- OodSupport::Group
- Includes:
- Comparable
- Defined in:
- lib/ood_support/group.rb
Overview
A helper object describing a Unix group’s details
Instance Attribute Summary collapse
-
#id ⇒ Integer
readonly
The id of the group.
-
#name ⇒ String
readonly
The name of the group.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
The comparison operator for sorting values.
-
#eql?(other) ⇒ Boolean
Checks whether two Group objects have the same group as well as that the object is in the Group class.
-
#hash ⇒ Integer
Generates a hash value for this object.
-
#initialize(group = Process.group) ⇒ Group
constructor
A new instance of Group.
-
#to_s ⇒ String
Convert object to string using group name as string value.
Constructor Details
#initialize(group = Process.group) ⇒ Group
Returns a new instance of Group.
17 18 19 20 21 22 23 24 25 |
# File 'lib/ood_support/group.rb', line 17 def initialize(group = Process.group) if group.is_a?(Integer) @id = group @name = Etc.getgrgid(@id).name else @name = group.to_s @id = Etc.getgrnam(@name).gid end end |
Instance Attribute Details
#id ⇒ Integer (readonly)
The id of the group
10 11 12 |
# File 'lib/ood_support/group.rb', line 10 def id @id end |
#name ⇒ String (readonly)
The name of the group
14 15 16 |
# File 'lib/ood_support/group.rb', line 14 def name @name end |
Instance Method Details
#<=>(other) ⇒ Integer
The comparison operator for sorting values
30 31 32 |
# File 'lib/ood_support/group.rb', line 30 def <=>(other) name <=> other end |
#eql?(other) ⇒ Boolean
Checks whether two Group objects have the same group as well as that the object is in the Group class
38 39 40 |
# File 'lib/ood_support/group.rb', line 38 def eql?(other) self.class == other.class && self == other end |
#hash ⇒ Integer
Generates a hash value for this object
44 45 46 |
# File 'lib/ood_support/group.rb', line 44 def hash [self.class, name].hash end |
#to_s ⇒ String
Convert object to string using group name as string value
50 51 52 |
# File 'lib/ood_support/group.rb', line 50 def to_s name end |