* 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
* 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
* 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 (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 (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 (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
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
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
* 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
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
* 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
* 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
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
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
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
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
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