Граф коммитов

53 Коммитов

Автор SHA1 Сообщение Дата
naruse 3e92b635fb Add frozen_string_literal: false for all files
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
2015-12-16 05:07:31 +00:00
marcandre 13d8bb0385 * lib/ostruct.rb: Have OpenStruct#dig raise if argument is not a symbol
nor a string. See [#11762]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-12 21:40:50 +00:00
nobu 482530680c OpenStruct#dig
* 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
2015-11-17 05:36:03 +00:00
eregon 3bf9b2f047 * lib/ostruct.rb: Finish defining OpenStruct attributes lazily.
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
2015-10-14 16:57:21 +00:00
nobu b1cfb98e9e ostruct.rb: fix NameError
* 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
2015-09-26 23:16:37 +00:00
zzak 7fa2155805 * lib/ostruct.rb: Move method definitions for getter/setter to be lazy
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
2015-09-26 16:05:52 +00:00
nobu da4942c9d7 ostruct.rb: match Symbol itself
* 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
2015-04-14 03:35:18 +00:00
nobu 759a31b4a3 Revert GH-808
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-08 07:07:59 +00:00
nobu 39ad417562 ostruct.rb: table
* 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
2015-01-05 05:27:31 +00:00
nobu 10ce99866f ostruct.rb: append suffixes to protected methods
* 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
2015-01-05 01:57:26 +00:00
marcandre f9a169fff2 * lib/ostruct.rb: raise NoMethodError with a #name and #args.
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
2013-10-23 15:14:17 +00:00
marcandre 5b5de3984e * lib/ostruct.rb (Struct#each_pair): Return an enumerator with size
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
2013-10-23 15:13:57 +00:00
marcandre 99d5d90f2f * lib/ostruct.rb (OpenStruct#delete): Use the converted argument.
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
2013-10-23 15:13:38 +00:00
marcandre b9e18abe4a * lib/ostruct.rb: Raise RuntimeError when modifying frozen instances
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
2013-10-23 15:13:19 +00:00
zzak dda10afc65 * lib/ostruct.rb: Typo in OpenStruct overview [Github Fixes #251]
Patch by Chun-wei Kuo


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-27 03:36:02 +00:00
marcandre e44e356b53 * lib/ostruct.rb: Add [] and []=, base on a patch by Thomas Sawyer
[ruby-core:42779] [Feature #6056]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-28 21:20:10 +00:00
marcandre 3785d2675a * lib/ostruct.rb: Also accept {Open}Struct as argument to new
[ruby-core:47476] [Feature #7007]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-28 21:19:50 +00:00
marcandre 22115ec87e * lib/ostruct.rb: Simplify code
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-28 21:19:32 +00:00
marcandre b4300d25c9 * lib/ostruct.rb: Add OpenStruct#eql? and OpenStruct#hash
[ruby-core:42651] [Bug #6029]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-28 21:19:15 +00:00
marcandre 15d4862b91 * lib/ostruct.rb (each_pair): Add #each_pair [#1400]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-28 21:18:53 +00:00
marcandre 2dafb0f47a * lib/ostruct.rb: Protect new_ostruct_member [ruby-core:42779] [#6056]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-28 21:18:32 +00:00
marcandre af29f7d2a3 * lib/ostruct.rb: Remove rdoc details on marshal_{load|dump} and fix rdoc
[ruby-core:42557] [ruby-core:42780]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-28 21:18:11 +00:00
nobu 770ddcdfe0 * hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods.
[Feature #6276]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-24 03:46:55 +00:00
naruse 62c9ecfa12 Revert r35339-35343 because of no tests.
* 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
2012-04-18 03:59:15 +00:00
marcandre db66739c7c * lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]
[ref #1400] [rubyspec:9e0250b2fc6f]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-16 03:16:25 +00:00
marcandre dfb1a71222 * lib/ostruct.rb (delete_field): Bug fix so previous value is returned.
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
2012-02-22 18:59:03 +00:00
marcandre 2d952c6d16 * lib/ostruct.rb: Create getters and setters after dup.
[Bug #6028] [rubyspecs:0380bcc]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-02-15 03:31:55 +00:00
marcandre 3281b90ecb * lib/ostruct.rb: Simplify and fix rdoc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-02-15 03:31:30 +00:00
drbrain ca96541149 * ext/pathname/lib/pathname.rb: Fix typos and grammar mistakes. Patch
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
2011-08-26 22:22:37 +00:00
marcandre a50bdcd6df * lib/ostruct.rb (method_missing): Handle [] and []= correctly.
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
2011-05-27 15:59:02 +00:00
drbrain c651520c13 * lib/ostruct.rb: Improve documentation. Patch by Franklin Webber.
[Ruby 1.9 - Bug #4761]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-22 23:46:08 +00:00
nobu 4ec86dcc57 * lib/ostruct.rb (OpenStruct#delete_field): also undefine
accessor methods.  [ruby-core:33010]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-11-03 05:17:25 +00:00
nobu 287a34ae0d * {ext,lib,test}/**/*.rb: removed trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-06 03:56:38 +00:00
nobu 1942710d42 * lib/ostruct.rb (modifiable): check if really frozen.
[ruby-core:22559]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-27 05:23:10 +00:00
nobu a4eb339564 * lib/ostruct.rb (OpenStruct#new_ostruct_member): checks if frozen.
[ruby-talk:328195], [ruby-core:22142]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-15 12:43:46 +00:00
yugui ed15422759 * lib/ostruct.rb (OpenStruct#inspect): fixed the recursion check.
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
2009-01-13 12:52:23 +00:00
nobu ef1ccbbc40 * lib/ostruct.rb (new_ostruct_member): Object#send no longer call
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
2005-09-12 23:09:39 +00:00
matz 48653d5ef0 * lib/ostruct.rb: a patch from Florian Gross <florgro@gmail.com>
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
2005-09-05 08:29:52 +00:00
matz 405a50a594 * eval.c (proc_invoke): prepare to pass a block from "call" method
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
2004-12-03 04:56:25 +00:00
matz 5847fadf7b * io.c (rb_file_initialize): [ruby-dev:25032]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-02 15:17:35 +00:00
matz c0acb3ce17 * io.c (rb_io_sysread): use temporary lock. [ruby-dev:24992]
* lib/ostruct.rb (OpenStruct::method_missing): check method
  duplication for -d.

* lib/ostruct.rb (OpenStruct::initialize): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-29 15:58:18 +00:00
matz 018837b84f * node.h (NODE_TYPESHIFT): allow 4 more bits for line numbers.
[ruby-talk:117841]

* ruby.h (FL_ABLE): nodes are not subject for flag operations.

* io.c (ARGF_FORWARD): should have specified argv explicitly,
  since we no longer have frame->argv saved.  [ruby-dev:24602]

* string.c (RESIZE_CAPA): check string attribute before modifying
  capacity member of string structure.  [ruby-dev:24594]

* ext/zlib/zlib.c (gzreader_gets): use memchr() to to gain
  performance.  [ruby-talk:117701]

* sprintf.c (rb_f_sprintf): raise ArgumentError for extra
  arguments, unless (digit)$ style used.

* io.c (rb_io_fptr_finalize): leave stdin/stdout/stderr open in
  interpreter termination.  [ruby-dev:24579]

* eval.c (frame_free): Guy Decoux solved the leak problem.
  Thanks.  [ruby-core:03549]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-10-27 09:29:26 +00:00
matz 919f456de8 * exception message clean-up by Ian Macdonald <ian@caliban.org>.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-03-29 07:54:38 +00:00
nobu 33e064afff * lib/ostruct.rb (OpenStruct#initialize_copy): should not share
members.  [ruby-dev:22966]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-02-20 10:11:25 +00:00
gsinclair 0425463a3d * lib/ostruct.rb: documented
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-02-19 13:42:30 +00:00
ntalbott fb1f07049f * lib/ostruct.rb: Added OpenStruct#==.
* test/ostruct/test_ostruct.rb: Added.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-09-25 00:03:11 +00:00
matz 1cece7f80f * lib/ostruct.rb (OpenStruct::method_missing): prohibit modifying
frozen OpenStruct. [ruby-talk:80214]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-08-26 14:54:51 +00:00
nobu c52339881c * instruby.rb: not rewrite installed scripts when dry-run mode.
* lib/ostruct.rb (OpenStruct::initialize): should symbolize keys
  instead of values.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-11-18 20:09:46 +00:00
nahi 8a442aa52a * ostruct.rb: keep NoMethodError message with Ruby itself.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-11-15 16:12:43 +00:00
nahi c0e98a1384 * observer.rb: raise NoMethodError instead of NameError. [ruby-dev:18788]
* ostruct.rb: ditto.  fix a bug in inspect which called String#+ with
  Symbol.  [ruby-dev:18788]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-11-14 22:46:00 +00:00