summaryrefslogtreecommitdiff
path: root/ruby
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2015-12-19 00:44:09 +0100
committerPatrick Simianer <p@simianer.de>2015-12-19 00:44:09 +0100
commit7375fdd7600fd83256d13644bc8b35dc2c71c2d0 (patch)
tree4ee0871b50aca3b5df730fc51cac20adf38101b7 /ruby
parent869e1c86d80dee01b39d447e741f9498d917a418 (diff)
ruby: module, split range
Diffstat (limited to 'ruby')
-rw-r--r--ruby/module.rb20
-rwxr-xr-xruby/split_range.rb27
2 files changed, 47 insertions, 0 deletions
diff --git a/ruby/module.rb b/ruby/module.rb
new file mode 100644
index 0000000..b25d603
--- /dev/null
+++ b/ruby/module.rb
@@ -0,0 +1,20 @@
+module Aaa
+ class Bbb
+ def initialize
+ puts "BBB"
+ end
+ end
+
+ def Aaa.q
+ puts "xxx"
+ end
+
+ def Aaa.bla
+ q
+ end
+end
+
+Aaa.bla
+
+a = Aaa::Bbb.new
+
diff --git a/ruby/split_range.rb b/ruby/split_range.rb
new file mode 100755
index 0000000..ee28c75
--- /dev/null
+++ b/ruby/split_range.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+
+a = (5..10)
+b = (8..9)
+
+def split_range a, b, index=0
+ return nil if a==b
+ aa = a.to_a
+ begin_split = b.first
+ end_split = b.last
+
+ p1 = aa[0..aa.index([begin_split-1,aa.first].max)]
+ p2 = aa[aa.index([end_split+1, aa.last].min)..aa.last]
+
+ if begin_split > a.first && end_split < a.last
+ return [(p1.first..p1.last), "X#{index}", (p2.first..p2.last)]
+ elsif begin_split == a.first
+ return ["X#{index}", (p2.first..p2.last)]
+ elsif end_split == a.last
+ return [(p1.first..p1.last), "X#{index}"]
+ end
+ return nil
+end
+
+puts split_range(a, b).to_s
+