Class: Weechat::Property

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

Instance Method Summary collapse

Constructor Details

#initialize(weechat_obj, property) ⇒ 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

#method_missing(m, *args, &block) ⇒ Object



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

#__freeze__Object



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

def __freeze__
  @frozen = true
end

#__property__Object



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

def __property__
  @property
end

#__weechat_obj__Object



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

def __weechat_obj__
  @weechat_obj
end