Skip to content

Commit

Permalink
Documented shortcuts Ops.get_foo Convert.to_foo
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Sep 12, 2014
1 parent 4a65a65 commit 99f7223
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/ruby/yast/convert.rb
Expand Up @@ -8,7 +8,26 @@ module Yast
# there is generated shortcuts for conversion to_<type>
# @deprecated ruby need not type conversion and int<->float conversion is explicit
module Convert
#generate shortcuts
# @!method self.to_boolean( object )
# @return [Boolean, nil] *object*, or `nil` if it is not a Boolean
# @!method self.to_string( object )
# @return [String, nil] *object*, or `nil` if it is not a String
# @!method self.to_symbol( object )
# @return [Symbol, nil] *object*, or `nil` if it is not a Symbol
# @!method self.to_integer( object )
# @return [Integer, nil] *object*, or `nil` if it is not a Integer
# @!method self.to_float( object )
# @return [Float, nil] *object*, or `nil` if it is not a Float
# @!method self.to_list( object )
# @return [Array, nil] *object*, or `nil` if it is not a Array
# @!method self.to_map( object )
# @return [Hash, nil] *object*, or `nil` if it is not a Hash
# @!method self.to_term( object )
# @return [Term, nil] *object*, or `nil` if it is not a Term
# @!method self.to_path( object )
# @return [Path, nil] *object*, or `nil` if it is not a Path
# @!method self.to_locale( object )
# @return [String, nil] *object*, or `nil` if it is not a String
Ops::SHORTCUT_TYPES.each do |type|
eval <<END
def self.to_#{type}(object)
Expand Down
25 changes: 23 additions & 2 deletions src/ruby/yast/ops.rb
Expand Up @@ -29,8 +29,9 @@ module Ops
'byteblock' => Yast::Byteblock
}

# Types for which we generate shortcut methods, e.g. {Yast::Ops.get_string} or
# {Yast::Convert.to_string}.
# Types for which we generate shortcut methods,
# e.g. {Yast::Ops.get_string}
# or {Yast::Convert.to_string}.
SHORTCUT_TYPES = [
"boolean",
"string",
Expand All @@ -44,6 +45,26 @@ module Ops
"locale"
]

# @!method self.get_boolean( obj, idx, def )
# @return [Boolean, nil] {Convert.to_boolean}({get}(obj, idx, def))
# @!method self.get_string( obj, idx, def )
# @return [String, nil] {Convert.to_string}({get}(obj, idx, def))
# @!method self.get_symbol( obj, idx, def )
# @return [Symbol, nil] {Convert.to_symbol}({get}(obj, idx, def))
# @!method self.get_integer( obj, idx, def )
# @return [Integer, nil] {Convert.to_integer}({get}(obj, idx, def))
# @!method self.get_float( obj, idx, def )
# @return [Float, nil] {Convert.to_float}({get}(obj, idx, def))
# @!method self.get_list( obj, idx, def )
# @return [Array, nil] {Convert.to_list}({get}(obj, idx, def))
# @!method self.get_map( obj, idx, def )
# @return [Hash, nil] {Convert.to_map}({get}(obj, idx, def))
# @!method self.get_term( obj, idx, def )
# @return [Term, nil] {Convert.to_term}({get}(obj, idx, def))
# @!method self.get_path( obj, idx, def )
# @return [Path, nil] {Convert.to_path}({get}(obj, idx, def))
# @!method self.get_locale( obj, idx, def )
# @return [String, nil] {Convert.to_locale}({get}(obj, idx, def))
Ops::SHORTCUT_TYPES.each do |type|
eval <<END, binding, __FILE__, __LINE__ + 1
def self.get_#{type}(object, indexes, default=nil, &block)
Expand Down

0 comments on commit 99f7223

Please sign in to comment.