Class: Object

Inherits:
BasicObject
Defined in:
lib/hotcocoa/core_extensions/object.rb,
lib/hotcocoa/kvo_accessors.rb

Overview

HotCocoa extensions for the Object class

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.kvo_array(key, &b) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/hotcocoa/kvo_accessors.rb', line 2

def self.kvo_array(key, &b)
  key = key.to_s
  capitalized_key = key[0].capitalize + key[1..-1]
  signatures = { :size      => { selector: :"countOf#{capitalized_key}",                  type_signature: "i@:",   flip: false },
                 :[]        => { selector: :"objectIn#{capitalized_key}AtIndex:",         type_signature: "@@:i",  flip: false },
                 :insert    => { selector: :"insertObject:in#{capitalized_key}AtIndex:",  type_signature: "v@:@i", flip: true  },
                 :delete_at => { selector: :"removeObjectFrom#{capitalized_key}AtIndex:", type_signature: "v@:i",  flip: false }
  }
  define_methods_with_signatures(signatures, &b)
end

.kvo_set(key, &b) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hotcocoa/kvo_accessors.rb', line 13

def self.kvo_set(key, &b)
  key = key.to_s
  capitalized_key = key[0].capitalize + key[1..-1]
  signatures = { :add       => { selector: :"add#{capitalized_key}Object:",    type_signature: "v@:@", flip: false },
                 :delete    => { selector: :"remove#{capitalized_key}Object:", type_signature: "v@:@", flip: false },
                 :merge     => { selector: :"add#{capitalized_key}:",          type_signature: "v@:@", flip: false },
                 :subtract  => { selector: :"remove#{capitalized_key}:",       type_signature: "v@:@", flip: false },
                 :set       => { selector: :"#{key}",                          type_signature: "@@:",  flip: false }
  }
  define_methods_with_signatures(signatures, &b)
end

Instance Method Details

#full_const_get(name) ⇒ Object

Object.full_const_get was taken from the ‘extlib’ project: http://github.com/sam/extlib which is released under a MIT License and copyrighted by Sam Smoot (2008).

Given a string, return the fully qualified constant name found in the receiver's namespace.

Examples:


Object.full_const_get('HotCocoa::Mappings') # => HotCocoa::Mappings
HotCocoa.full_const_get('Mappings') # => HotCocoa::Mappings

Parameters:

  • name (String)

    the constant to get

Returns:

  • the constant corresponding to the name, if it exists



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hotcocoa/core_extensions/object.rb', line 22

def full_const_get name
  list = name.split('::')
  list.shift if list.first.empty?
  obj = self

  list.each do |x|
    # This is required because const_get tries to look for constants in the
    # ancestor chain, but we only want constants that are HERE
    obj = obj.const_defined?(x) ? obj.const_get(x) : obj.const_missing(x)
  end

  obj
end