Module: FRuby::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/utils.rb

Instance Method Summary collapse

Instance Method Details

#has_instance_method?(obj, method_name) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/utils.rb', line 8

def has_instance_method?(obj, method_name)
  obj.instance_methods.include? method_name.to_s
end

#multiple_all?(*args, &block) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/utils.rb', line 18

def multiple_all?(*args, &block)
  multiple_each(*args) do |*each_args|
    return false unless block.call(*each_args)
  end
  true
end

#multiple_each(*args, &block) ⇒ Object



12
13
14
15
16
# File 'lib/utils.rb', line 12

def multiple_each(*args, &block)
  args.first.size.times do |index|
    block.call(args.map { |arg| arg[index] })
  end
end

#rand_condition_method_name(prefix, size = 8) ⇒ Object



3
4
5
6
# File 'lib/utils.rb', line 3

def rand_condition_method_name(prefix, size = 8)
  alphabet = ('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a
  "__#{prefix}_condition_#{Array.new(size) { alphabet[rand(alphabet.size)] }.join}__"
end