source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/xsd/codegen/methoddef.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 1.2 KB
Line 
1# XSD4R - Generating method definition code
2# Copyright (C) 2004 NAKAMURA, Hiroshi <[email protected]>.
3
4# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5# redistribute it and/or modify it under the same terms of Ruby's license;
6# either the dual license version in 2003, or any later version.
7
8
9require 'xsd/codegen/gensupport'
10require 'xsd/codegen/commentdef'
11
12
13module XSD
14module CodeGen
15
16
17class MethodDef
18 include GenSupport
19 include CommentDef
20
21 attr_accessor :definition
22
23 def initialize(name, *params)
24 unless safemethodname?(name)
25 raise ArgumentError.new("name '#{name}' seems to be unsafe")
26 end
27 @name = name
28 @params = params
29 @comment = nil
30 @definition = yield if block_given?
31 end
32
33 def dump
34 buf = ""
35 buf << dump_comment if @comment
36 buf << dump_method_def
37 buf << dump_definition if @definition and [email protected]?
38 buf << dump_method_def_end
39 buf
40 end
41
42private
43
44 def dump_method_def
45 if @params.empty?
46 format("def #{@name}")
47 else
48 format("def #{@name}(#{@params.join(", ")})")
49 end
50 end
51
52 def dump_method_def_end
53 format("end")
54 end
55
56 def dump_definition
57 format(@definition, 2)
58 end
59end
60
61
62end
63end
Note: See TracBrowser for help on using the repository browser.