Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Ruby の次のメソッドは、ハッシュを先頭に追加した入力文字列をスキャンするのに役立ちますか?
def foo(bar) (bar.scan(/^#/).empty?) ? "##{bar}" : bar end
あなたは同じことを達成することができます:
if bar.start_with?('#') bar else "##{bar}" end
または三項を使用する:
bar.start_with? '#' ? bar : "##{bar}"