Upgrade to 1.46.0
[platform/upstream/nghttp2.git] / third-party / mruby / lib / mruby-core-ext.rb
1 autoload :Pathname, 'pathname'
2
3 class Object
4   class << self
5     def attr_block(*syms)
6       syms.flatten.each do |sym|
7         class_eval "def #{sym}(&block);block.call(@#{sym}) if block_given?;@#{sym};end"
8       end
9     end
10   end
11 end
12
13 class String
14   def relative_path_from(dir)
15     Pathname.new(File.expand_path(self)).relative_path_from(Pathname.new(File.expand_path(dir))).to_s
16   end
17
18   def relative_path
19     relative_path_from(Dir.pwd)
20   end
21 end
22
23 def _pp(cmd, src, tgt=nil, options={})
24   return if Rake.verbose
25
26   width = 5
27   template = options[:indent] ? "%#{width*options[:indent]}s %s %s" : "%-#{width}s %s %s"
28   puts template % [cmd, src, tgt ? "-> #{tgt}" : nil]
29 end