[#74190] [Ruby trunk Feature#12134] Comparison between `true` and `false` — duerst@...
Issue #12134 has been updated by Martin D端rst.
3 messages
2016/03/07
[#74269] Type systems for Ruby — Rob Blanco <ml@...>
Dear ruby-core,
5 messages
2016/03/10
[#74395] [Ruby trunk Feature#12142] Hash tables with open addressing — shyouhei@...
Issue #12142 has been updated by Shyouhei Urabe.
3 messages
2016/03/17
[ruby-core:74421] [Ruby trunk Feature#11997] A method to read a file with interpolations
From:
mame@...
Date:
2016-03-17 13:13:06 UTC
List:
ruby-core #74421
Issue #11997 has been updated by Yusuke Endoh.
-1. I don't think that this is suitable as a core feature. We should leave such a thing to a library like erb.
----------------------------------------
Feature #11997: A method to read a file with interpolations
https://bugs.ruby-lang.org/issues/11997#change-57544
* Author: Tsuyoshi Sawada
* Status: Feedback
* Priority: Normal
* Assignee:
----------------------------------------
I request a single method that reads a file while interpreting interpolated Ruby code in it (in the current context). For example, suppose I have a file `foo.txt`.
foo.txt
~~~
#{char * 20}
Hello, my name is #{name}.
#{char * 20}
~~~
I am not sure about what method name the proposed feature should have, and on which class it should be defined, but let's temporarily call it `File.eval`. Then I would like to do:
~~~ruby
char = "*"
name = "John Doe"
File.eval("foo.txt") # => "********************\nHello, my name is John Doe.\n********************\n"
~~~
The use case that I have in mind is to easily create template engines/preprocessors, or do an equivalent of what such software do on the fly within a script. There are tools like erb, SCSS, haml, etc., but those force a particular syntax, and they are full fledged software with their own parsing capability, which means it takes an extra time to parse, and the sortware may have their own bugs. I often feel that I do not want to adopt any of the syntax forced in those limited choice of template/preprocessing software, but do it in a freer way.
Using what we have currently, I can do it with:
~~~ruby
eval('"' + File.read("foo.txt") + '"')
~~~
but that looks cumbersome, and wish if Ruby had a C-level built-in capability for doing that. I believe that would encourage wide range of Ruby users to more freely create their own templating system.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>