How does Ruby 1.9 handle character cases in source code?

In Ruby 1.8 and earlier

Foo

- a constant (class, module, or other constant). While

Foo

is a variable. The main difference is as follows:

module Foo
  bar = 7
  BAZ = 8
end

Foo::BAZ
# => 8

Foo::bar
# NoMethodError: undefined method 'bar' for Foo:Module

That all is well and good, but Ruby 1.9 allows the source code of UTF-8 . So what is uppercase or lowecase, as far as that goes? What about (strict subset) or Ɖfoo?

Is there a general rule?

Further:

Ruby-core is already looking at some of the math operators. for example

module Kernel
  def(num)
    ...
  end
  def(*args)
    ...
  end
end

will allow

x = √2
y = ∑(1, 45, ...)

I would like to see

my_proc = λ { |...| ... }

x ∈ my_enumerable  # same as my_enumerable.include?(x)

my_infinite_range = (1..∞)

return 'foo' if x ≠ y

2.21 ≈ 2.2
+5
source share
5 answers

IRB UTF-8, script (/tmp/utf_test.rb).

"λ" :

# encoding: UTF-8
λ = 'foo'
puts λ

# from the command line:
> ruby -KU /tmp/utf_test.rb
foo

"λ" :

# encoding: UTF-8
Kernel.class_eval do
  alias_method :λ, :lambda
end

(λ { puts 'hi' }).call

# from the command line:
> ruby -KU /tmp/utf_test.rb:
hi

:

# encoding: UTF-8
Object.const_set :λ, 'bar'

# from the command line:
> ruby -KU /tmp/utf_test.rb:
utf_test.rb:2:in `const_set': wrong constant name λ (NameError)

:

# encoding: UTF-8
Object.const_set :Λ, 'bar'

# from the command line:
> ruby -KU /tmp/utf_test.rb:
utf_test.rb:2:in `const_set': wrong constant name Λ (NameError)

, ASCII ( /^[A-Z]/).

0

, .

Matz , Ruby 1.9, String#upcase String#downcase, ASCII .

, , -ascii .

- 1.9 ?

+3

, Ruby , UTF8 , , , DON ' T DO THAT

+2

my_proc = λ { |...| ... }

x ∈ my_enumerable  # same as my_enumerable.include?(x)

my_infinite_range = (1..∞)

return 'foo' if x ≠ y

2.21 ≈ 2.2

, - : P

+1

Ruby 1.9.2-p0 (YARV) , (.. Foo:: bar # = > # NoMethodError: undefined method 'bar' Foo: Module). , , , , .

:

"á".upcase
=> "á"
"á" == "Á".downcase
=> false
+1

All Articles