Module: Enumerable

Included in:
Bioinform::Collection
Defined in:
lib/bioinform/support/same_by.rb,
lib/bioinform/support/collect_hash.rb

Instance Method Summary collapse

Instance Method Details

#collect_hash(&block) ⇒ Object

%wC G T.collect_hash{|k| [k*2, k*3] } # ==> => “AAA”, “CC” => “CCC”, “GG” => “GGG”, “TT” => “TTT”



4
5
6
# File 'lib/bioinform/support/collect_hash.rb', line 4

def collect_hash(&block)
  block_given?  ?  Hash[ collect(&block) ]  :  Hash[ collect{|k,v| [k,v]} ]
end

#same_by?(&block) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
5
6
7
8
9
10
11
# File 'lib/bioinform/support/same_by.rb', line 2

def same_by?(&block)
  return true if empty?
  if block_given?
    first_result = yield(first)
    all?{|el| first_result == yield(el)}
  else
    first_result = first
    all?{|el| first_result == el}
  end
end