Project

General

Profile

Actions

Feature #5583

closed

Optionally typing

Added by technohippy (Yasushi ANDO) over 12 years ago. Updated over 11 years ago.

Status:
Rejected
Target version:
-
[ruby-core:40806]

Description

Although I know all of you dislike static typing it cannot be denied that there are some people aspire for introducing it in ruby. The dartlang solved the problem in unique way called Optionally Typing. In Dart you can declare types for variables but they are ignored by the compiler with default options.

It looks superb idea for me so that I introduced the optionally typing to ruby as a trial. You can write types for variables if you want then the ruby completely ignores these dirts.

Sample code:

def method(arg)
  arg   
end 

def typed_method(arg) : String
  arg   
end 

def fully_typed_method(arg : String) : String
  arg   
end 

var = 'var'
puts var 

var_with_type : String = 'var_with_type'
puts var_with_type

var_from_method : String = typed_method('var_from_method')
puts var_from_method

@ivar : String = fully_typed_method('@ivar')
puts @ivar

Results:

$ ./truby -Ilib -I. truby_test.rb 
var 
var_with_type
var_from_method
@ivar

I attached my poor patch. Thanks for your consideration.


Files

optionally-typing.patch (3.84 KB) optionally-typing.patch technohippy (Yasushi ANDO), 11/07/2011 12:49 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #6711: Optional typing and method overloadingRejectedmatz (Yukihiro Matsumoto)07/09/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0