source: EcnlProtoTool/trunk/mruby-1.2.0/tasks/ruby_ext.rake@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 1.6 KB
Line 
1class Object
2 class << self
3 def attr_block(*syms)
4 syms.flatten.each do |sym|
5 class_eval "def #{sym}(&block);block.call(@#{sym}) if block_given?;@#{sym};end"
6 end
7 end
8 end
9end
10
11class String
12 def relative_path_from(dir)
13 Pathname.new(File.expand_path(self)).relative_path_from(Pathname.new(File.expand_path(dir))).to_s
14 end
15
16 def relative_path
17 relative_path_from(Dir.pwd)
18 end
19
20 # Compatible with 1.9 on 1.8
21 def %(params)
22 if params.is_a?(Hash)
23 str = self.clone
24 params.each do |k, v|
25 str.gsub!("%{#{k}}") { v }
26 end
27 str
28 else
29 if params.is_a?(Array)
30 sprintf(self, *params)
31 else
32 sprintf(self, params)
33 end
34 end
35 end
36end
37
38class Symbol
39 # Compatible with 1.9 on 1.8
40 def to_proc
41 proc { |obj, *args| obj.send(self, *args) }
42 end
43end
44
45module Enumerable
46 # Compatible with 1.9 on 1.8
47 def each_with_object(memo)
48 return to_enum :each_with_object, memo unless block_given?
49 each { |obj| yield obj, memo }
50 memo
51 end
52end
53
54$pp_show = true
55
56if $verbose.nil?
57 if Rake.respond_to?(:verbose) && !Rake.verbose.nil?
58 if Rake.verbose.class == TrueClass
59 # verbose message logging
60 $pp_show = false
61 else
62 $pp_show = true
63 Rake.verbose(false)
64 end
65 else
66 # could not identify rake version
67 $pp_show = false
68 end
69else
70 $pp_show = false if $verbose
71end
72
73def _pp(cmd, src, tgt=nil, options={})
74 return unless $pp_show
75
76 width = 5
77 template = options[:indent] ? "%#{width*options[:indent]}s %s %s" : "%-#{width}s %s %s"
78 puts template % [cmd, src, tgt ? "-> #{tgt}" : nil]
79end
Note: See TracBrowser for help on using the repository browser.