Hi, ALL:
I am happy because i learned a lot last night from this fourm.
Now, I encounter another challenge. Here is my code:
class Fastqfile
attr_accessor :offset
def initialize file
@file = file
@offset ||= 33
end
def each_records
File.foreach(@file).each_slice(4).map {|elem|
if block_given?
yield elem.map(&:chomp)
else
elem.map(&:chomp)
end
}.to_enum
end
def each_ids
each_records {|id,seq,_id,qv|
if block_given?
yield id
else
id
end
}.to_enum
end
def each_reads
each_records {|id,seq,_id,qv|
if block_given?
yield seq
else
seq
end
}.to_enum
end
def each_quals
each_records {|id,seq,_id,qv|
if block_given?
yield decode(qv)
else
decode(qv)
end
}.to_enum
end
private
def decode(qv)
qv.chars.map {|q| q.ord - 33 }
end
end
There are many similar methods within my code. I hope to make it DRY.
At the beginning. I try to use method_missing to solve my question. But
i feel it’s not a good way.
In my case , method_missing may lead to debug issue.
Could someboy give me some suggestion?
Thanks a lot.