Class: JSONable

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

Direct Known Subclasses

Profile, Profile::HomeBrew, Profile::Shell

Instance Method Summary collapse

Instance Method Details

#from_json!(string) ⇒ Object



57
58
59
60
61
# File 'lib/bashman.rb', line 57

def from_json!(string)
    JSON.load(string).each do |var, val|
        self.instance_variable_set(var, val)
    end
end

#to_hashObject



44
45
46
47
48
49
50
# File 'lib/bashman.rb', line 44

def to_hash
    hash = {}
    self.instance_variables.each do |var|
        hash[var] = self.instance_variable_get(var)
    end
    hash
end

#to_jsonObject



52
53
54
55
# File 'lib/bashman.rb', line 52

def to_json
    hash = self.to_hash
    hash.to_json
end