aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ostruct.rb
Commit message (Collapse)AuthorAgeFilesLines
* ostruct.rb: improve fix for OpenStruct.allocate + #respond_to?eregon2017-04-011-7/+1
| | | | | | | | | * lib/ostruct.rb (OpenStruct#respond_to_missing?): this makes OpenStruct#respond_to? works on any OpenStruct instance, just like Kernel#respond_to? does, without workarounds. [ruby-core:80292] [Bug #13358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ostruct.rb: refine visibility failure messagenobu2017-03-281-4/+7
| | | | | | | * lib/ostruct.rb (method_missing): raise an exception with proper visibility message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ostruct.rb: fix OpenStruct.allocatenobu2017-03-241-1/+4
| | | | | | | | * lib/ostruct.rb (OpenStruct.allocate): initialize an instance variable directly, without calling `intialize` method which may be overridden in a subclass. [ruby-core:80292] [Bug #13358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* lib/ostruct.rb: [DOC] revise docs for OpenStructstomar2017-03-111-68/+108
| | | | | | | | | | | | | | | | | | | | * update paragraph on implementation: define_singleton_method is used, not define_method * add call-seq with return values for each_pair * adopt description of dig from Array and Hash * fix description of the hash method * :nodoc: initialize_copy, respond_to_missing? * other small improvements, e.g. use the term `attribute' in the docs (instead of `member'), which is clearer for users of the class * improve code examples: e.g. use more consistent style (always use double quotes, drop `p' and `puts', ...), update inspect output, use example data that is not prone to change (like population) * add more code examples * fix some small errors and grammar [ruby-core:79265] [Bug #13159] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* lib/ostruct.rb: Fix returned value of each_pair.marcandre2017-02-031-0/+1
| | | | | | From a patch by Marcus Stollsteimer. [Fixes #13169] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: [DOC] fix position of nodoc directive.ktsj2016-04-091-2/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ostruct.rb: make internal methods privatenobu2016-03-031-9/+18
| | | | | | | | * lib/ostruct.rb (modifiable?, new_ostruct_member!, table!): rename methods for internal use with suffixes and make private, [ruby-core:71069] [Bug #11587] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Fix case of frozen object with initializer.marcandre2016-01-011-1/+1
| | | | | | Bug revealed by RubySpec [ruby-core:72639] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ostruct.rb: deferred accessorsnobu2015-12-311-0/+5
| | | | | | | | * lib/ostruct.rb (freeze): define deferred accessors before freezing to get rid of an error when just reading frozen OpenStruct. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Fix new_ostruct_member to correctly avoid redefinitionmarcandre2015-12-311-1/+1
| | | | | | [#11901] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ostruct.rb: respond_to?nobu2015-12-291-0/+5
| | | | | | | | * lib/ostruct.rb (OpenStruct): make respond_to? working on just-allocated objects for workaround of Psych. [ruby-core:72501] [Bug #11884] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add frozen_string_literal: false for all filesnaruse2015-12-161-0/+1
| | | | | | When you change this to true, you may need to add more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Have OpenStruct#dig raise if argument is not a symbolmarcandre2015-12-121-1/+1
| | | | | | nor a string. See [#11762] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* OpenStruct#dignobu2015-11-171-0/+18
| | | | | | | * lib/ostruct.rb (dig): Implement OpenStruct#dig [Feature #11688] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Finish defining OpenStruct attributes lazily.eregon2015-10-141-3/+9
| | | | | | | | | | | Patch by @sferik in [GH-1037]: https://github.com/ruby/ruby/pull/1037 This commit is an addendum to https://github.com/ruby/ruby/pull/1033. It: 1. lazily defines attribute accessors for copied and marshaled objects, 2. returns nil when an attribute reader is not defined, and 3. defines respond_to_missing? to maintain the same respond_to? behavior git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ostruct.rb: fix NameErrornobu2015-09-261-2/+7
| | | | | | | * lib/ostruct.rb (delete_field): do not raise NameError for existing keys. [Fix GH-1033] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Move method definitions for getter/setter to be lazyzzak2015-09-261-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by @sferik in [GH-1033]: https://github.com/ruby/ruby/pull/1033 Instead of defining two methods -- a reader and writer -- for each OpenStruct attribute when it is initialized, define them lazily, the first time either one is called. This adheres to the principle of "pay for use": methods that are never accessed are never defined. This optimization makes initialization an order of magnitude faster for objects with 100 attributes. In the worst-case scenario, where every attribute is accessed, performance is no worse than it is today. Benchmark --------- require 'benchmark/ips' require 'ostruct' N = 100 ATTRS = (:aa..:zz).take(N) HASH = Hash[ATTRS.map { |x| [x, x] }] def ostruct OpenStruct.new(HASH) end Benchmark.ips do |x| x.report('ostruct') { ostruct } end ------------------------------------------------- before 2.279k (± 8.8%) i/s - 11.395k after 24.702k (±12.8%) i/s - 122.600k ------------------------------------------------- git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ostruct.rb: match Symbol itselfnobu2015-04-141-2/+1
| | | | | | | * lib/ostruct.rb (method_missing): get rid of creating temporary string object for method name, match Symbol itself. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Revert GH-808nobu2015-01-081-13/+12
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ostruct.rb: tablenobu2015-01-051-2/+1
| | | | | | * lib/ostruct.rb (OpenStruct#table): revert for JSON. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ostruct.rb: append suffixes to protected methodsnobu2015-01-051-13/+15
| | | | | | | | * lib/ostruct.rb (modifiable?, new_ostruct_member!, table!): append suffixes to protected methods so that they will not clash with assigned members. [Fix GH-806] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49145 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: raise NoMethodError with a #name and #args.marcandre2013-10-231-1/+3
| | | | | | | | Patch by Kenichi Kamiya. [Fixes GH-383] * test/ostruct/test_ostruct.rb: Added tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (Struct#each_pair): Return an enumerator with sizemarcandre2013-10-231-1/+1
| | | | | | | | Patch by Kenichi Kamiya. [Fixes GH-383] * test/ostruct/test_ostruct.rb: Added tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (OpenStruct#delete): Use the converted argument.marcandre2013-10-231-1/+1
| | | | | | | | Patch by Kenichi Kamiya. [Fixes GH-383] * test/ostruct/test_ostruct.rb: Added tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43403 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Raise RuntimeError when modifying frozen instancesmarcandre2013-10-231-1/+1
| | | | | | | | instead of TypeError. Patch by Kenichi Kamiya. [Fixes GH-383] * test/ostruct/test_ostruct.rb: Added tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Typo in OpenStruct overview [Github Fixes #251]zzak2013-02-271-2/+2
| | | | | | | Patch by Chun-wei Kuo git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Add [] and []=, base on a patch by Thomas Sawyermarcandre2012-10-281-2/+22
| | | | | | [ruby-core:42779] [Feature #6056] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Also accept {Open}Struct as argument to newmarcandre2012-10-281-3/+5
| | | | | | [ruby-core:47476] [Feature #7007] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Simplify codemarcandre2012-10-281-6/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Add OpenStruct#eql? and OpenStruct#hashmarcandre2012-10-281-2/+19
| | | | | | [ruby-core:42651] [Bug #6029] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (each_pair): Add #each_pair [#1400]marcandre2012-10-281-0/+14
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Protect new_ostruct_member [ruby-core:42779] [#6056]marcandre2012-10-281-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Remove rdoc details on marshal_{load|dump} and fix rdocmarcandre2012-10-281-22/+4
| | | | | | [ruby-core:42557] [ruby-core:42780] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods.nobu2012-04-241-0/+13
| | | | | | | [Feature #6276] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Revert r35339-35343 because of no tests.naruse2012-04-181-12/+17
| | | | | | | | | | | | | | * hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276] * lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276] * struct.c: Add Struct#to_h [Feature #6276] * object.c: Add NilClass#to_h [Feature #6276] * hash.c: Add Hash#to_h [Feature #6276] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]marcandre2012-04-161-17/+12
| | | | | | [ref #1400] [rubyspec:9e0250b2fc6f] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (delete_field): Bug fix so previous value is returned.marcandre2012-02-221-1/+1
| | | | | | | | Patch by Nick Recobra [Bug #6063] * test/ostruct/test_ostruct.rb: Test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34755 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Create getters and setters after dup.marcandre2012-02-151-0/+1
| | | | | | [Bug #6028] [rubyspecs:0380bcc] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Simplify and fix rdoc.marcandre2012-02-151-15/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/pathname/lib/pathname.rb: Fix typos and grammar mistakes. Patchdrbrain2011-08-261-3/+3
| | | | | | | | | | | | | | | | by Luke Gruber. [#5203] * ext/pty/lib/expect.rb: ditto * lib/mathn.rb: ditto * lib/net/http.rb: ditto * lib/open-uri.rb: ditto * lib/ostruct.rb: ditto * lib/tempfile.rb: ditto * lib/thread.rb: ditto * lib/weakref.rb: ditto * sample/webrick/httpproxy.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (method_missing): Handle [] and []= correctly.marcandre2011-05-271-3/+3
| | | | | | Based on a patch by Caius Durling, bug #4179 [ruby-core:33792] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: Improve documentation. Patch by Franklin Webber.drbrain2011-05-221-18/+113
| | | | | | | [Ruby 1.9 - Bug #4761] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (OpenStruct#delete_field): also undefinenobu2010-11-031-1/+3
| | | | | | accessor methods. [ruby-core:33010] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * {ext,lib,test}/**/*.rb: removed trailing spaces.nobu2009-03-061-4/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (modifiable): check if really frozen.nobu2009-02-271-2/+4
| | | | | | | [ruby-core:22559] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (OpenStruct#new_ostruct_member): checks if frozen.nobu2009-02-151-8/+12
| | | | | | | [ruby-talk:328195], [ruby-core:22142] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (OpenStruct#inspect): fixed the recursion check.yugui2009-01-131-13/+11
| | | | | | | | | Patch by Kornelius Kalnbach. [ruby-core:20992]. * test/ostruct/test_ostruct.rb: test for inspect. Patch by Kornelius Kalnbach. [ruby-core:20992]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb (new_ostruct_member): Object#send no longer callnobu2005-09-121-3/+4
| | | | | | | | | | | | | private methods. [ruby-dev:27044] * test/rss/test_dublincore.rb, test/rss/test_trackback.rb, test/ruby/test_eval.rb, test/socket/test_socket.rb: ditto. * test/ruby/test_lambda (test_call_with_block): lambda makes new scope for formal block parameter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/ostruct.rb: a patch from Florian Gross <florgro@gmail.com>matz2005-09-051-11/+30
| | | | | | | | | | | | | | | merged to allow recursive inspect (and to_s) for OpenStruct. [ruby-core:05532] * lib/observer.rb: a patch from nornagon <nornagon@gmail.com> merged to allow arbitrary names for update methods. [ruby-core:05416] * eval.c (rb_f_fcall): new method to avoid inefficiency of obj.instance_eval{send(...)} tricks. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * eval.c (proc_invoke): prepare to pass a block from "call" methodmatz2004-12-031-10/+6
| | | | | | | | | | | | | | | to a Proc generated by Method#to_proc. [ruby-dev:25031] * eval.c (rb_yield_0): actually passes a block given to "call". * object.c (convert_type): use rb_respond_to() again. this fix is based on [ruby-dev:25021] * eval.c (rb_respond_to): funcall respond_to? if it's redefined. [ruby-dev:25021] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e