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

66 Коммитов

Автор SHA1 Сообщение Дата
shyouhei f2a91397fd Add uplevel keyword to Kernel#warn and use it
If uplevel keyword is given, the warning message is prepended
with caller file and line information and the string "warning: ".
The use of the uplevel keyword makes Kernel#warn format output
similar to how rb_warn formats output.

This patch modifies net/ftp and net/imap to use Kernel#warn
instead of $stderr.puts or $stderr.printf, since they are used
for printing warnings.

This makes lib/cgi/core and tempfile use $stderr.puts instead of
warn for debug logging, since they are used for debug printing
and not for warning.

This does not modify bundler, rubygems, or rdoc, as those are
maintained outside of ruby and probably wish to remain backwards
compatible with older ruby versions.

rb_warn_m code is originally from nobu, but I've changed it
so that it only includes the path and lineno from uplevel
(not the method), and also prepends the string "warning: ",
to make it more similar to rb_warn.

From: Jeremy Evans code@jeremyevans.net
Signed-off-by: Urabe Shyouhei shyouhei@ruby-lang.org


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 11:56:25 +00:00
marcandre e565c838ce lib/ostruct.rb: Use frozen literals.
Patch adapted from Espartaco Palma. [GH-1714] [Bug #14000]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24 18:08:15 +00:00
eregon a6456054ae ostruct.rb: improve fix for OpenStruct.allocate + #respond_to?
* 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
2017-04-01 10:30:48 +00:00
nobu a20715c8ed ostruct.rb: refine visibility failure message
* 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
2017-03-28 09:21:58 +00:00
nobu cd911b9367 ostruct.rb: fix OpenStruct.allocate
* 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
2017-03-24 12:16:54 +00:00
stomar 44fbaaae46 lib/ostruct.rb: [DOC] revise docs for OpenStruct
* 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
2017-03-11 21:32:46 +00:00
marcandre 4d7b999c77 lib/ostruct.rb: Fix returned value of each_pair.
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
2017-02-03 18:25:28 +00:00
ktsj 997df3ad01 * lib/ostruct.rb: [DOC] fix position of nodoc directive.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-09 13:39:32 +00:00
nobu 7c89ca5431 ostruct.rb: make internal methods private
* 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
2016-03-03 05:09:02 +00:00
marcandre 9543908c9f * lib/ostruct.rb: Fix case of frozen object with initializer.
Bug revealed by RubySpec [ruby-core:72639]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-01 17:27:38 +00:00
nobu 6e5967e2ae ostruct.rb: deferred accessors
* 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
2015-12-31 18:26:46 +00:00
marcandre 2f2a5c3ae9 * lib/ostruct.rb: Fix new_ostruct_member to correctly avoid redefinition
[#11901]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-31 05:37:21 +00:00
nobu 15960b37e8 ostruct.rb: respond_to?
* 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
2015-12-29 03:48:36 +00:00
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