source: EcnlProtoTool/trunk/mruby-2.1.1/lib/mruby-core-ext.rb@ 439

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

mrubyを2.1.1に更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 677 bytes
Line 
1autoload :Pathname, 'pathname'
2
3class 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
11end
12
13class 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
21end
22
23def _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]
29end
Note: See TracBrowser for help on using the repository browser.