Class: NSDictionary

Inherits:
Object show all
Defined in:
lib/cocoa/sugarcube-files/nsdictionary.rb,
lib/cocoa/sugarcube-anonymous/anonymous.rb,
lib/cocoa/sugarcube-nsuserdefaults/nsuserdefaults.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.read_from(path_or_url) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/cocoa/sugarcube-files/nsdictionary.rb', line 5

def read_from(path_or_url)
  case path_or_url
  when NSURL
    self.dictionaryWithContentsOfURL(path_or_url)
  when NSString
    self.dictionaryWithContentsOfFile(path_or_url)
  else
    false
  end
end

Instance Method Details

#to_nsuserdefaultsObject



50
51
52
# File 'lib/cocoa/sugarcube-nsuserdefaults/nsuserdefaults.rb', line 50

def to_nsuserdefaults
  self.each_with_object({}) { |(key, val), h| h[key] = val.to_nsuserdefaults }
end

#to_objectObject



89
90
91
# File 'lib/cocoa/sugarcube-anonymous/anonymous.rb', line 89

def to_object
  SugarCube::Anonymous[self]
end

#write_to(path_or_url, atomically = true) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/cocoa/sugarcube-files/nsdictionary.rb', line 18

def write_to(path_or_url, atomically=true)
  case path_or_url
  when NSURL
    self.writeToURL(path_or_url, atomically: atomically)
  when NSString
    self.writeToFile(path_or_url, atomically: atomically)
  else
    false
  end
end