summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
+