[#23231] What do you think about changing the return value of Kernel#require and Kernel#load to the source encoding of the required file? — =?ISO-8859-15?Q?Wolfgang_N=E1dasi-Donner?= <ed.odanow@...>

Dear Ruby developers and users!

8 messages 2009/04/17

[#23318] [Feature #1408] 0.1.to_r not equal to (1/10) — Heesob Park <redmine@...>

Feature #1408: 0.1.to_r not equal to (1/10)

19 messages 2009/04/26

[ruby-core:23203] Re: [Bug #1336] Change in string representation of Floats

From: Ryan Davis <ryand-ruby@...>
Date: 2009-04-14 08:22:47 UTC
List: ruby-core #23203
On Apr 13, 2009, at 00:19 , Eero Saynatkari wrote:

> I think I am in agreement, but I  would like to amend the
> description of the three to confirm:
>
>  #to_s:    String representing the object mainly for output
>  #inspect: Internal details, ivars etc., mainly for debug
>  #dump:    Round-trip/evalable representation


I agree with this and thought/hoped that was the original intent of  
inspect.

In smalltalk (a stream-based IO system) they use #printOn: like our  
puts/to_s and  #storeOn: for something like a meld of your #dump and  
#inspect. storeOn: outputs the code that would eval to an object equal/ 
equivalent to the original (see below). Unfortunately, our #inspect  
for non-core objects don't default to a ruby expression.

I think #to_ruby would be a better name than #dump. It doesn't clash  
with Marshal/YAML and matches #to_s and friends.

> storeOn: aStream
> 	"Append to the argument aStream a sequence of characters that is an
> 	expression whose evaluation creates an object similar to the  
> receiver."
>
> 	aStream nextPut: $(.
> 	self class isVariable
> 		ifTrue: [aStream nextPutAll: '(', self class name, ' basicNew: ';
> 					store: self basicSize;
> 					nextPutAll: ') ']
> 		ifFalse: [aStream nextPutAll: self class name, ' basicNew'].
> 	1 to: self class instSize do:
> 		[:i |
> 		aStream nextPutAll: ' instVarAt: ';
> 			store: i;
> 			nextPutAll: ' put: ';
> 			store: (self instVarAt: i);
> 			nextPut: $;].
> 	1 to: self basicSize do:
> 		[:i |
> 		aStream nextPutAll: ' basicAt: ';
> 			store: i;
> 			nextPutAll: ' put: ';
> 			store: (self basicAt: i);
> 			nextPut: $;].
> 	aStream nextPutAll: ' yourself)'


In This Thread