In Files

  • mrbgems/mruby-struct/mrblib/struct.rb

Parent

Struct

Public Instance Methods

each(&block) click to toggle source

Calls the given block for each element of self and pass the respective element.

ISO 15.2.18.4.4

 
               # File mrbgems/mruby-struct/mrblib/struct.rb, line 14
def each(&block)
  self.class.members.each{|field|
    block.call(self[field])
  }
  self
end
            
each_pair(&block) click to toggle source

Calls the given block for each element of self and pass the name and value of the respectiev element.

ISO 15.2.18.4.5

 
               # File mrbgems/mruby-struct/mrblib/struct.rb, line 27
def each_pair(&block)
  self.class.members.each{|field|
    block.call(field.to_sym, self[field])
  }
  self
end
            
select(&block) click to toggle source

Calls the given block for each element of self and returns an array with all elements of which block is not false.

ISO 15.2.18.4.7

 
               # File mrbgems/mruby-struct/mrblib/struct.rb, line 40
def select(&block)
  ary = []
  self.class.members.each{|field|
    val = self[field]
    ary.push(val) if block.call(val)
  }
  ary
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus