[#89430] [Ruby trunk Misc#15229] DevelopersMeeting201801122Japan — mame@...
Issue #15229 has been reported by mame (Yusuke Endoh).
3 messages
2018/10/17
[#89555] [Ruby trunk Feature#15251] Hash aset should deduplicate non tainted string — chopraanmol1@...
Issue #15251 has been updated by chopraanmol1 (Anmol Chopra).
3 messages
2018/10/25
[#89583] [PATCH] vm_trace.c (postponed_job_register): only hit main thread — Eric Wong <normalperson@...>
@hsbt: I post here on ruby-core because I hit errors with
5 messages
2018/10/27
[#89584] Re: [PATCH] vm_trace.c (postponed_job_register): only hit main thread
— Koichi Sasada <ko1@...>
2018/10/27
thank you for you patch.
[#89590] Re: [PATCH] vm_trace.c (postponed_job_register): only hit main thread
— Eric Wong <normalperson@...>
2018/10/28
Koichi Sasada <[email protected]> wrote:
[#89621] [Ruby trunk Bug#14867] Process.wait can wait for MJIT compiler process — Greg.mpls@...
Issue #14867 has been updated by MSP-Greg (Greg L).
4 messages
2018/10/29
[#89622] Re: [Ruby trunk Bug#14867] Process.wait can wait for MJIT compiler process
— Eric Wong <normalperson@...>
2018/10/29
[email protected] wrote:
[#89627] [Ruby trunk Bug#14867] Process.wait can wait for MJIT compiler process — takashikkbn@...
Issue #14867 has been updated by k0kubun (Takashi Kokubun).
3 messages
2018/10/30
[#89654] [Ruby trunk Bug#14867] Process.wait can wait for MJIT compiler process — takashikkbn@...
Issue #14867 has been updated by k0kubun (Takashi Kokubun).
4 messages
2018/10/31
[#89655] Re: [Ruby trunk Bug#14867] Process.wait can wait for MJIT compiler process
— Eric Wong <normalperson@...>
2018/10/31
[email protected] wrote:
[ruby-core:89245] [Ruby trunk Feature#15192] Introduce a new "shortcut assigning" syntax to convenient setup instance variables
From:
shyouhei@...
Date:
2018-10-02 06:42:49 UTC
List:
ruby-core #89245
Issue #15192 has been updated by shyouhei (Shyouhei Urabe).
This isn't Matz's but my experience. When "we want to do something more than just assigning instance variables", that "something" tends to include cancellation of creating new object -- maybe because we are returning a cached instance, or because we are raising an exception. In order to properly handle such situations #initialize tends to be too late to "do something". When I write a complex constructor that tends to happen inside of .new directly, and #initialize eventually becomes a series of instance variable assignments. One of such example is: https://github.com/shyouhei/xmp2assert/blob/master/lib/xmp2assert/quasifile.rb
----------------------------------------
Feature #15192: Introduce a new "shortcut assigning" syntax to convenient setup instance variables
https://bugs.ruby-lang.org/issues/15192#change-74270
* Author: jjyr (Jinyang Jiang)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Motivation:
Introduce a new syntax for convenient setup instance variables for objects.
The problem:
Currently, setup instance variables in Ruby is too verbose.
Basically, we need to write the meaningless assigning code again and again to assign variables
``` ruby
class Person
def initialize(name:, age:, gender:, country:)
@name = name
@age = age
@gender = gender
@country = country
end
end
# we can use Struct to avoiding this
Person = Struct.new(:name, :age, :gender, :country, keyword_init: true)
# let's see a real-world case, which can't use Struct to describe an initializing process, from https://github.com/ciri-ethereum/ciri/blob/748985ccf7a620a2e480706a5a6b38f56409d487/lib/ciri/devp2p/server.rb#L54
# Because we want to do something more than just assigning instance variables
class Server
def initialize(private_key:, protocol_manage:, bootstrap_nodes: [],
node_name: 'Ciri', tcp_host: '127.0.0.1', tcp_port: 33033)
@private_key = private_key
@node_name = node_name
@bootstrap_nodes = bootstrap_nodes
@protocol_manage = protocol_manage
server_node_id = NodeID.new(@private_key)
caps = [Cap.new(name: 'eth', version: 63)]
@handshake = ProtocolHandshake.new(version: BASE_PROTOCOL_VERSION, name: @node_name, id: server_node_id.id, caps: caps)
@tcp_host = tcp_host
@tcp_port = tcp_port
@dial = Dial.new(bootstrap_nodes: bootstrap_nodes, private_key: private_key, handshake: @handshake)
@network_state = NetworkState.new(protocol_manage)
@dial_scheduler = DialScheduler.new(@network_state, @dial)
end
end
# Introduce a new "shortcut assigning" syntax for convenient setup
class Person
# use @ prefix to describe instance variables.
def initialize(@name:, @age:, @gender:, @country:)
end
# equal to
def initialize2(name:, age:, gender:, country:)
@name = name
@age = age
@gender = gender
@country = country
end
# it should also work on position style arguments
def initialize2(@name, @age, @gender, @country)
end
end
# Our real-world case can be rewritten as below
class Server
def initialize(@private_key:, @protocol_manage:, @bootstrap_nodes: [],
@node_name: 'Ciri', @tcp_host: '127.0.0.1', @tcp_port: 33033)
server_node_id = NodeID.new(@private_key)
caps = [Cap.new(name: 'eth', version: 63)]
@handshake = ProtocolHandshake.new(version: BASE_PROTOCOL_VERSION, name: @node_name, id: server_node_id.id, caps: caps)
@dial = Dial.new(bootstrap_nodes: @bootstrap_nodes, private_key: @private_key, handshake: @handshake)
@network_state = NetworkState.new(@protocol_manage)
@dial_scheduler = DialScheduler.new(@network_state, @dial)
end
end
# consider to keep consistency, this "shortcut assigning" syntax should work for non-initialize methods
class Foo
def bar(@still_works)
p @still_works
end
end
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>