How to save files using rpg maker xp - ruby

I was wondering because RPG Maker XP Uses Ruby for its scripting language, Can I save/read files using ruby?
I wrote this code but got syntax errors...
File.open("user.json", "r") do |f|
f.each_line do |ln|
put "JSON"
end
end

Related

What is the difference between Ruby win32api and win32ole?

A piece of ruby code using win32ole
require 'win32ole'
ie = WIN32OLE.new('InternetExplorer.Application')
ie.visible = true
ie.gohome
Some code using win32api
require "Win32API"
message = "This is a sample Windows message box generated using Win32API"
title = "Win32API from Ruby"
api = Win32API.new('user32', 'MessageBox',['L', 'P', 'P', 'L'],'I')
api.call(0,message,title,0)
First one opens up internet explorer and the second one displays a message box.
Simply saying both seems to be able to access the OS and make it do stuff. Is win32ole a subset of win32api or is it the other way around? What is the difference between the two?
win32ole is for interoperating with libraries & applications that have been written to act as OLE/COM servers, see What is COM? for an explanation of that technology.
win32api interacts with the operating system API (Win32) which is also where OLE/COM are implemented, but win32ole exists to conveniently abstract away much of the complexities involved in making use of COM via its lower level API.

How Ruby Is Run

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

How to require a chinese named ruby file?

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?

How can I print syntax-highlighted Ruby code?

I use TextMate for my Ruby editing, but when printing files, the code isn't syntax highlighted. Are there any good programs for printing out well-formatted color-highlighted Ruby code?
A good solution which I use is to print from TextMate via vim which gives you a syntax-highlighted and line-numbered result (or however you choose to configure it.) In addition to vim it requires ps2pdf but these are easy to install with macports etc.
The only limitation is that the file needs to be saved first.
See this page, which shows how to set up the macro as a TextMate 'command'.
I don't know if it's relevant in Mac-world, but the SciTE editor that's bundled
with the one-click installer for Windows prints nicely in colour on our HP Laserjet. I haven't tried printing from any of the various IDEs - I ought to try it.
I'd probably use Ultraviolet to create an HTML file that's syntax-highlighted to print out...
The syntax gem is pretty awesome.
require 'hpricot'
require 'syntax/convertors/html'
def filter_content(content)
h = Hpricot(content)
c = Syntax::Convertors::HTML.for_syntax "ruby"
h.search('//pre[#class="ruby"]') do |e|
e.inner_html = c.convert(e.inner_text,false)
end
h.to_s
end
Edit: Oh, you are referring to printing... Well you could do convert it to HTML and then print it from your browser.
Apparently it is difficult to communicate to the printer that a *.txt-equivalent file needs to be colorized but it obviously can be done. TextMate's creator has communicated simply that he doesn't think it is important enough of a feature to have which basically means it is extremely difficult to implement.
Aptana can do this thing no problem but it takes forever to load.
Enter vim. vim is probably already installed on your computer.
vim filename.m
:syntax on
:hardcopy
Again, there won't be any prompt for which printer to use, so make sure your system's default printer is set correctly.
If you had to use the :syntax on command to get vim to colorize your code:
To set vim by default to do syntax-based coloring:
nano ~/.vimrc
syntax on
save & quit
Thanks, boulder_ruby
A couple of additional points at the end of 2016 (2 years 10 months later):
If you're on Windows, you cannot count on VIM being already installed. Membership in Stack Overflow does improve the odds, but probably not to 90%). However VIM for Windows is easy to get. www.vim.org/download.php
Macs come with MacVim by default.
On a Mac, using MacVim, following your advice, I carefully set the default printer to one where I could empty the queue before wasting paper on testing.
Then I used the :hardcopy VIM command. The printed version went straight to PDF and opened in Preview. It never showed up in the default printer queue.
Also, edavey above points to http://biztos.blogspot.com/2008/06/printing-with-textmate-vim-and-friends.html which contains a link to the TextMate Help page on printing. The TextMate help says:
There are plans to improve the printing capabilities, but until then,
there is also a command in the Source bundle (View Source as PDF)
which produces a PDF from the current source using enscript and has
syntax highlighting enabled for supported languages.
That suggests (I haven't figured it out the "Source bundle" yet) that you can go straight to PDF, with syntax coloring, from TextMate. If I figure that out, I'll add something here (eventually).
I hope this helps.

How can I add metadata to MP3s for Windows Media player from a script

I previously asked this question, but now I've gotten lazy and I'm trying to figure out how to do it from script (vbscript specifically). Specifically what I want to know is:
How can I set Artist, Song Title,
Genre, etc on a mp3 file from
vbscript?
Thanks
Here are instructions.
There's a DLL required which can be gotten from freely available Creative Blaster drivers.
Also see this project - seems to support many languages including vbscript
If you're not wedded to vbscript idea, Perl has a very nice library MP3::Tag or somesuch (just google for perl+mp3+tag); assuming you're game for installing Windows Perl (Strawberry or Active Perl)

Resources