Class: Object

Inherits:
BasicObject
Includes:
InstanceExecHelper
Defined in:
lib/edango/helpers/object.rb

Overview

EDango - torrent ticket extractor.

Copyright (C) 2010  Dmitrii Toksaitov

This file is part of EDango.

EDango is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

EDango is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with EDango. If not, see <http://www.gnu.org/licenses/>.

Defined Under Namespace

Modules: InstanceExecHelper

Instance Method Summary collapse

Instance Method Details

#instance_exec(*args, &block) ⇒ Object

noinspection RubyScope,RubyDeadCode



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/edango/helpers/object.rb', line 48

def instance_exec(*args, &block)
  method_name = "__instance_exec_#{Thread.current.object_id.abs}_#{object_id.abs}"

  InstanceExecHelper.module_eval { define_method(method_name, &block) }

  result = nil

  begin
    result = send(method_name, *args)
  ensure
    InstanceExecHelper.module_eval { undef_method(method_name) } rescue nil
  end

  result
end

#nil_or_empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/edango/helpers/object.rb', line 38

def nil_or_empty?
  nil? or try(:empty?)
end

#try(method_name, *args, &block) ⇒ Object



34
35
36
# File 'lib/edango/helpers/object.rb', line 34

def try(method_name, *args, &block)
  send(method_name, *args, &block) if respond_to?(method_name, true)
end

#valid?(item, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/edango/helpers/object.rb', line 20

def valid?(item, *args, &block)
  result = item ? true : false

  if result
    args.each do |object|
      (result = false; break) unless object
    end

    yield if block_given?
  end

  result
end