Class: Weechat::Property

Inherits:
Blankslate show all
Defined in:
lib/weechat/property.rb

Instance Method Summary (collapse)

Constructor Details

- (Property) initialize(weechat_obj, property)



7
8
9
10
11
12
13
# File 'lib/weechat/property.rb', line 7

def initialize(weechat_obj, property)
  @old_obj     = weechat_obj.__get_property(property)
  @weechat_obj = weechat_obj
  @property    = property
  @settable    = weechat_obj.settable_property?(property)
  @frozen      = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(m, *args, &block)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/weechat/property.rb', line 27

def method_missing(m, *args, &block)
  if @frozen
    obj = @old_obj
  else
    obj = @weechat_obj.__get_property(@property)
  end
  ret = obj.__send__(m, *args, &block)

  if (@old_obj != obj) && @settable && !@frozen
    @weechat_obj.set_property(@property, obj)
  end

  unless @frozen
    begin
      @old_obj = obj.dup
    rescue TypeError
      @old_obj = obj
    end
  end

  ret
end

Instance Method Details

- (Object) __freeze__



23
24
25
# File 'lib/weechat/property.rb', line 23

def __freeze__
  @frozen = true
end

- (Object) __property__



19
20
21
# File 'lib/weechat/property.rb', line 19

def __property__
  @property
end

- (Object) __weechat_obj__



15
16
17
# File 'lib/weechat/property.rb', line 15

def __weechat_obj__
  @weechat_obj
end