class KvoExample

Attributes

age[RW]
items[RW]
label[RW]

Public Class Methods

new() click to toggle source
# File spec/motion/core/kvo_spec.rb, line 10
def initialize
  @items = [ "Apple", "Banana", "Chickpeas" ]
  @age = 1

  @label = text_class.alloc.initWithFrame [[0,0],[320, 30]]

  set_text "Foo"
end

Public Instance Methods

get_text() click to toggle source

Test helper

# File spec/motion/core/kvo_spec.rb, line 21
def get_text
  @label.send(text_method_name)
end
observe_collection(&block) click to toggle source
# File spec/motion/core/kvo_spec.rb, line 37
def observe_collection(&block)
  observe(self, :items, &block)
end
observe_label(&block) click to toggle source
# File spec/motion/core/kvo_spec.rb, line 29
def observe_label(&block)
  observe(@label, text_method_name, &block)
end
observe_label!(&block) click to toggle source
# File spec/motion/core/kvo_spec.rb, line 33
def observe_label!(&block)
  observe!(@label, text_method_name, &block)
end
set_text(text) click to toggle source
# File spec/motion/core/kvo_spec.rb, line 25
def set_text(text)
  @label.send("#{text_method_name}=", text)
end
text_class() click to toggle source
# File spec/motion/core/kvo_spec.rb, line 53
def text_class
  App.osx? ? NSTextField : UILabel
end
text_method_name() click to toggle source
# File spec/motion/core/kvo_spec.rb, line 49
def text_method_name
  App.osx? ? :stringValue : :text
end
unobserve_label() click to toggle source
# File spec/motion/core/kvo_spec.rb, line 41
def unobserve_label
  unobserve(@label, text_method_name)
end
unobserve_label!() click to toggle source
# File spec/motion/core/kvo_spec.rb, line 45
def unobserve_label!
  unobserve!(@label, text_method_name)
end
update_collection() click to toggle source
# File spec/motion/core/kvo_spec.rb, line 57
def update_collection
  self.items += [ "Rice" ]
end