summaryrefslogtreecommitdiffstats
path: root/lib/xsd/codegen/methoddef.rb
diff options
context:
space:
mode:
author(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-03 15:38:36 +0000
committer(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-03 15:38:36 +0000
commit6133b96d61c705c7aefdf6f577f0da5796bc522d (patch)
treece6b571d063d031d1b5cba3ba7671ca138405a3a /lib/xsd/codegen/methoddef.rb
parent70105b2706511a6358a32b805fb55f187e942698 (diff)
downloadruby-6133b96d61c705c7aefdf6f577f0da5796bc522d.tar.gz
ruby-6133b96d61c705c7aefdf6f577f0da5796bc522d.tar.xz
ruby-6133b96d61c705c7aefdf6f577f0da5796bc522d.zip
This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/xsd/codegen/methoddef.rb')
-rw-r--r--lib/xsd/codegen/methoddef.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/xsd/codegen/methoddef.rb b/lib/xsd/codegen/methoddef.rb
new file mode 100644
index 000000000..797a4f024
--- /dev/null
+++ b/lib/xsd/codegen/methoddef.rb
@@ -0,0 +1,63 @@
+# XSD4R - Generating method definition code
+# Copyright (C) 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'xsd/codegen/gensupport'
+require 'xsd/codegen/commentdef'
+
+
+module XSD
+module CodeGen
+
+
+class MethodDef
+ include GenSupport
+ include CommentDef
+
+ attr_accessor :definition
+
+ def initialize(name, *params)
+ unless safemethodname?(name)
+ raise ArgumentError.new("#{name} seems to be unsafe")
+ end
+ @name = name
+ @params = params
+ @comment = nil
+ @definition = yield if block_given?
+ end
+
+ def dump
+ buf = ""
+ buf << dump_comment if @comment
+ buf << dump_method_def
+ buf << dump_definition if @definition
+ buf << dump_method_def_end
+ buf
+ end
+
+private
+
+ def dump_method_def
+ if @params.empty?
+ format("def #{@name}")
+ else
+ format("def #{@name}(#{@params.join(", ")})")
+ end
+ end
+
+ def dump_method_def_end
+ format("end")
+ end
+
+ def dump_definition
+ format(@definition, 2)
+ end
+end
+
+
+end
+end