Last change
on this file since 328 was 321, checked in by coas-nagasima, 7 years ago |
文字コードを設定
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-ruby;charset=UTF-8
|
File size:
1.6 KB
|
Line | |
---|
1 | class 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
|
---|
9 | end
|
---|
10 |
|
---|
11 | class 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
|
---|
36 | end
|
---|
37 |
|
---|
38 | class Symbol
|
---|
39 | # Compatible with 1.9 on 1.8
|
---|
40 | def to_proc
|
---|
41 | proc { |obj, *args| obj.send(self, *args) }
|
---|
42 | end
|
---|
43 | end
|
---|
44 |
|
---|
45 | module 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
|
---|
52 | end
|
---|
53 |
|
---|
54 | $pp_show = true
|
---|
55 |
|
---|
56 | if $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
|
---|
69 | else
|
---|
70 | $pp_show = false if $verbose
|
---|
71 | end
|
---|
72 |
|
---|
73 | def _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]
|
---|
79 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.