Class: RubyScriptWriter
- Inherits:
-
Object
- Object
- RubyScriptWriter
- Defined in:
- lib/rubyscriptwriter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#r ⇒ Object
readonly
Returns the value of attribute r.
Instance Method Summary collapse
- #comment(*args) ⇒ Object
- #indent ⇒ Object
-
#initialize ⇒ RubyScriptWriter
constructor
A new instance of RubyScriptWriter.
- #outdent ⇒ Object
- #put_class(class_name, superclass_name = nil) {|_self| ... } ⇒ Object
- #put_coding(coding = 'utf-8') ⇒ Object
- #put_method(method_name, *arguments) {|_self| ... } ⇒ Object
- #put_simple_method(method_name, *method_code) ⇒ Object
- #puts(*args) ⇒ Object
- #tabs ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ RubyScriptWriter
Returns a new instance of RubyScriptWriter.
6 7 8 9 |
# File 'lib/rubyscriptwriter.rb', line 6 def initialize @r = StringIO.new @tab_count = 0 end |
Instance Attribute Details
#r ⇒ Object (readonly)
Returns the value of attribute r.
4 5 6 |
# File 'lib/rubyscriptwriter.rb', line 4 def r @r end |
Instance Method Details
#comment(*args) ⇒ Object
49 50 51 |
# File 'lib/rubyscriptwriter.rb', line 49 def comment(*args) puts "# ", *args end |
#indent ⇒ Object
11 12 13 |
# File 'lib/rubyscriptwriter.rb', line 11 def indent @tab_count += 1 end |
#outdent ⇒ Object
15 16 17 |
# File 'lib/rubyscriptwriter.rb', line 15 def outdent @tab_count -= 1 end |
#put_class(class_name, superclass_name = nil) {|_self| ... } ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/rubyscriptwriter.rb', line 19 def put_class(class_name,superclass_name = nil) puts "class #{class_name}#{ superclass_name && " < #{superclass_name}"}" indent yield self outdent puts "end" puts end |
#put_coding(coding = 'utf-8') ⇒ Object
45 46 47 |
# File 'lib/rubyscriptwriter.rb', line 45 def put_coding(coding = 'utf-8') comment 'coding: ', coding end |
#put_method(method_name, *arguments) {|_self| ... } ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubyscriptwriter.rb', line 32 def put_method(method_name,*arguments) if arguments.empty? puts "def ", method_name else puts "def ", method_name, "(", arguments.join(','), ")" end indent yield self outdent puts "end" puts end |
#put_simple_method(method_name, *method_code) ⇒ Object
28 29 30 |
# File 'lib/rubyscriptwriter.rb', line 28 def put_simple_method(method_name,*method_code) puts "def " + method_name + "; " + method_code.join + "; end" end |
#puts(*args) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/rubyscriptwriter.rb', line 53 def puts(*args) if args.empty? r.puts return self end args.compact! r.puts tabs + args.join unless args.empty? self end |
#tabs ⇒ Object
63 64 65 |
# File 'lib/rubyscriptwriter.rb', line 63 def tabs " " * @tab_count end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/rubyscriptwriter.rb', line 67 def to_s r.string end |