Module: Ruboto::Util::CodeFormatting
- Included in:
- XMLElement
- Defined in:
- lib/ruboto/util/code_formatting.rb
Instance Method Summary collapse
- #if_else(condition, if_clause, else_clause = []) ⇒ Object
-
#method_call(return_type, method_name, parameters = [], exceptions = nil, body_clause = []) ⇒ Object
Methods for formatting code.
- #try_catch(try_clause, catch_clause) ⇒ Object
Instance Method Details
#if_else(condition, if_clause, else_clause = []) ⇒ Object
13 14 15 |
# File 'lib/ruboto/util/code_formatting.rb', line 13 def if_else(condition, if_clause, else_clause = []) ["if (#{condition}) {", if_clause.indent, else_clause.compact.empty? ? nil : "} else {", else_clause.indent, "}"] end |
#method_call(return_type, method_name, parameters = [], exceptions = nil, body_clause = []) ⇒ Object
Methods for formatting code
8 9 10 11 |
# File 'lib/ruboto/util/code_formatting.rb', line 8 def method_call(return_type, method_name, parameters=[], exceptions=nil, body_clause=[]) ["public #{"#{return_type} " unless return_type.nil? || return_type.empty?}#{method_name}(" + parameters.map{|i| "#{i[1]} #{i[0]}"}.join(", ") + ") #{" throws #{exceptions.join(', ')}" if exceptions && exceptions.any?}{", body_clause.indent, "}"] end |
#try_catch(try_clause, catch_clause) ⇒ Object
17 18 19 |
# File 'lib/ruboto/util/code_formatting.rb', line 17 def try_catch(try_clause, catch_clause) ["try {", try_clause.indent, "} catch (RaiseException re) {", catch_clause.indent, "}"] end |