summaryrefslogtreecommitdiff
path: root/lib/oxidized/string.rb
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-04-15 21:27:54 +0300
committerSaku Ytti <saku@ytti.fi>2014-04-15 21:27:54 +0300
commitff15057823db09509f76512d59ed87c316d882dc (patch)
tree8fd8bd4d7bee41e76dc76ebc9275be5431c11232 /lib/oxidized/string.rb
parent8abe0b299990fba0e12875634368922abe2710df (diff)
Use String subclass in model#cmd
Will allow convenience methods such as cmd :all do |cfg| cfg.pop.shift end instead of: cmd :all do |cfg| cfg.each_line.to_a[1..-2].join end And what ever convenience configs we come up with
Diffstat (limited to 'lib/oxidized/string.rb')
-rw-r--r--lib/oxidized/string.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/oxidized/string.rb b/lib/oxidized/string.rb
new file mode 100644
index 0000000..b334eaa
--- /dev/null
+++ b/lib/oxidized/string.rb
@@ -0,0 +1,13 @@
+module Oxidized
+ # Used in models, contains convenience methods
+ class String < String
+ # @return [Oxidized::String] copy of self with last line removed
+ def pop
+ Oxy::String.new each_line.to_a[0..-2].join
+ end
+ # @return [Oxidized::String] copy of self with first line removed
+ def shift
+ Oxy::String.new each_line.to_a[1..-1].join
+ end
+ end
+end