How to require a chinese named ruby file, for example require '测试'!
Why are you using Chinese characters to name files?
I would highly recommend against that. From my experience contemporary software (including operating systems) does not handle such files correctly in most cases.
How to require a chinese named ruby file, for example require '测试'!
Just
require '测试'
Why would the language of the filename matter anyway?
Related
I just started learning Ruby and I ran this command:
vim --version
The output looks like this (look at the yellow circle):
Which means that my Vim does not include the 'ruby' function.
But it seems my Vim supports Ruby fairly well:
q1: Is there any problem with my Ruby programming with the -ruby?
q2: How can I enable Ruby function in Vim?
The functionality on the second screenshot is given by installing the vim-ruby plugin.
The internal Ruby support is to allow people to write plugins and scripts for Vim using Ruby and it's not strictly necessary for what you seem to want to accomplish.
If you REALLY want to add Ruby support, you can always build Vim from source (or get a package with it already built). I suggest you to look into Vim's homepage for more info on this matter.
The difference you are missing is between using Vim to program in a language such as Ruby, and using a given language to program Vim.
Writing Ruby code using Vim is enabled by Vim's native syntax files, as well as various third-party plugins available for Vim. This is the case for many, many languages, not only those mentioned in the :version screen (Perl, Python, and Ruby). You can use Vim to write code in C, Scala, PHP, Javascript, and many other languages, with support for syntax highlighting, smart indenting, and so on.
Writing Vim functions and plugins can only be done in a small set of languages. Natively, Vim code is always written in its own language, Vimscript. However, Vimscript is notoriously difficult to deal with, and most people will not already know it. So Vim also has the ability to use plugins written in other languages, such as Python or Ruby. This enables people to use a more familiar language for plugin development.
However, using those languages requires binding to an interpreter for the language, and this must be decided at the time Vim is compiled. The :version screen is telling you that for your installation of Vim, the Ruby support was not enabled, so you can not write plugins using Ruby, nor can you use any available plugins which were written in Ruby.
Notice that +python is present, so you can use Python plugins (but -python3 is there too, meaning that you do not have Python 3.x support built in).
I come from an object oriented programming background, and have picked up Ruby as a hobby. It looks like a great language. My questions are:
Can you use any ol' test editor, write your ruby file, save it with a .rb extension and open it in the terminal?
Is this the most common method of using Ruby (Or other script languages), rather than with an IDE?
How do I close external programs on my Mac with ruby? What I will be doing with Ruby has a lot to do with opening files and commanding them. I was using AppleScript but want to convert. I've tried:
system open "John/Applications/TextEdit.app"
And it didn't close.
I'm on Windows but I'll try to answer your questions as good as possible, most of the stuff is OS independent.
For questions 1 and 2: You can use one of the following ways to edit and run Ruby scripts.
IRB (Interactive RuBy shell included with Ruby)
websites like http://tryruby.org/levels/1/challenges/0
An IDE such as:
RedMine
KomodoEdit
Eclipse with plugin (not that easy to configure)
not really necessary because Ruby code is short and easy to remember, kind of pseudocode, the advantage is in the beginning when you don't know the commands and structures and for debugging
voordeel = debuggen is makkelijker
Editor with a Run-optie like Textpad, Notepad++, Sublime Text..
The last one is my favorite, there are packages for Ruby but Ruby support is in the basic installation, you can edit your code with syntax-coloring and suggestions, run your code and the result is captured in a separate tab. It is the most widely used way of Ruby coding also.
In Windows I use the following way to run external programs and capture the result. I believe it to be working on a Mac also. The external shell and program is closed after the last end.
answer = ""
command = %Q{java -jar test.jar #{$parameter1} #{$parameter2}"}
IO.popen(command+" 2>&1") do |pipe|
pipe.sync = true
while str = pipe.gets
answer << str
end
end
#the answer variable holds all the output lines
I have found alot of .NET barcode reader/generators but not many for Ruby. Any recommendations on GEMS or someway to generate dtaamatrix barcodes and the ability to read datamatrix barcodes in PDF/TIFF files?
I'd the same problem a few months ago. There is a gem named "semacode" which use a native extension to generate datamatrix codes but it's buggy (adds a space in front of every string).
I would suggest Libdmtx through the system command which works fine for me. Afaik there is also an ruby adapter to this library but I the shell is okay for my project.
So ruby 1.9 is really nice in that it'll automatically require rubygems, and hence when you call require 'somegem' without first requiring rubygems it'll work, and that's generally awesome.
But I have a ton of shell scripts using ruby, and they generally don't rely on rubygems. Shell tools should run instantly, and loading rubygems for nothing is a major drag, mostly because it involves a bunch of disk operations with scattered small files.
I want to be able to tell ruby, when running these shell scripts, to skip loading gems. Ideally, something like #!ruby --no-rubygems in the shebang line.
Is there such a thing? Or maybe a compile option that'll tell ruby rubygems must be required manually?
Yes, you can use the --disable-gems option.
Note that whether or not passing options in the shebang line works depends on your operating system. Some operating systems don't support passing options at all, some only support passing one option or argument.
So, if you have for example
#!/usr/bin/env ruby
Then it's pretty unlikely that you will be able to attach the option to the end. If OTOH you change that to
#!/usr/local/bin/ruby --disable-gems
Then you have hardwired the location of the Ruby binary into your script.
And of course there are operating systems that don't interpret shebang lines at all. (After all, they were never specified in any standard, and aren't even properly documented.)
An alternative would be to set the RUBYOPT environment variable in your shell environment and simply switch to a different environment with RUBYOPT unset (or set to -w, my personal favorite) for your Ruby development.
I would like all my toolkit to use UTF-8 but find that some tools on Windows seem to use CP1252 (which appears to be Windows-specific). Does this create output which is incompatible and if so at which codepoints? If so, can I do anything about it?
(I don't completely understand the issues so I'd be grateful for basic education on these encodings).
Tools hard-coding for code page 1252 on Windows is very unlikely. Much more likely is that it happens to be the default code page on your machine. 1252 is used in Western Europe and the Americas. It is configured in Control Panel, Regional and Language options. They've been using different names for it, on Win7 it is in the Administrative tab, Change System Locale.
Yes, many tools use the default code page unless they have a good reason to chose another encoding. The BOM is such a good reason. Notable examples are Notepad (unless you change the Encoding in the File + Open dialog to something else than Ansi) and C/C++ compilers. There typically isn't anything special you need to do to use the default code page. Guessing the correct code page for a text file when you don't have a BOM is impossible to do accurately. Google "bush hid the facts" for a very amusing war story.
Six years old and still relevant: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
Now, about your question: Yes, there are still tools out there that choke on UTF-8 files. But more and more tools are "getting it". If you're developing your own stuff, you might want to look into Python 3 where all strings are Unicode. The philosophy is to convert all your inputs into Unicode (if necessary) as early as possible, and reconvert them to a target encoding as late as possible. There are toolkits out there that will do a good job of guessing the encoding of a particular file (for example, Mark Pilgrim's chardet, a port of Mozilla's encoding detector). This is nice if you're working with files that don't specify an encoding.
CP1252 and UTF-8 are the same for all characters < 128. They differ above that. So if you stick to English and stay away from diacritical marks these will be the same.
Most of the Windows tools will use whatever is set as the current user's current codepage, which will default to 1252 for US Windows. You can change that to another codepage pretty easily. But UTF-8 is NOT one of the available codepage options for Windows. (I wish it was).
Some utilities under Windows will understand the UTF-8 byte-order mark at the start of a file. Unfortunately I don't know how to determine if this will work except to try it.
UTF-8 is supported on Windows but not as a current codepage. You can use UTF-8 for converting to/from it but you cannot set is as current codepage.
First do not try to waste time by setting the codepage - this approach will remind you of Sisyphus myth - you can't really solve the problem using codepages, you have to use Unicode.
The only real solution for you is to build your application as Unicode so it will use UTF-16 and to convert to/from UTF-8 on in/out operations. This is done quite simple because fopen supports reading or writing UTF-8.
Regarding the usage of other Windows tools with UTF-8 file, you should not be aware because if the tool is able to work with ASCII it will work with UTF-8 (even so it may not be able to distinguish between Unicode chars but at least it will be able to load/parse the files).
BTW, You forgot to specify what programming language are you using and what Windows tools are you considering for usage.
Also, if you ware interested about more internationalization stuff please visit my blog.i18n.ro