Class: Object

Inherits:
BasicObject
Defined in:
lib/most/helpers/object.rb

Overview

Most - Modular Open Software Tester.

Copyright (C) 2009  Dmitrii Toksaitov

This file is part of Most.

Most 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.

Most 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 Most. If not, see <http://www.gnu.org/licenses/>.

Instance Method Summary collapse

Instance Method Details

#first_valid(item, *items) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/most/helpers/object.rb', line 36

def first_valid(item, *items)
  result = item

  if result.nil?
    items.each do |object|
      unless object.nil?
        result = object; break
      end
    end
  end

  result
end

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



50
51
52
# File 'lib/most/helpers/object.rb', line 50

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
33
34
# File 'lib/most/helpers/object.rb', line 20

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

  if result
    args.each do |objects|
      unless objects
        result = false; break;
      end
    end

    yield block if block_given?
  end

  result
end